I have just installed perfect scroll, the jQuery plugin, and it works great but I can't find a parameter to start the content at the bottom of my div. I want to have to scroll up on page load, not to have to scroll down.
Normally with jQuery I would just do:
$(nav_message_list).prop({ scrollTop: $(nav_message_list).prop("scrollHeight")});
But that seems to have no effect.
Current code:
$(".chat_person").click(function ()
{
if (!$(".chat_content_wrap").is(":visible"))
{
$(".chat_content_wrap").fadeIn(300, function ()
{
$('#message_list').perfectScrollbar('update');
$(nav_message_list).prop({ scrollTop: $(nav_message_list).prop("scrollHeight")});
});
}
});
$("#message_list").perfectScrollbar();
To auto scroll a page from top to bottom we can use scrollTop() and height() method in jquery. In this method pass the document's height in scrollTop method to scroll.
Use element. scroll() to Scroll to Bottom of Div in JavaScript. You can use element. scroll() to scroll to the bottom of an element.
To use you just need to press CTRL+ Left click of your mouse and drag the mouse a bit in the direction you want to scroll the page. For example, if you want to scroll up to the page automatically, click CTRL+ left click and slightly move your mouse upwards, the tool will start scrolling up the page.
scroll(function() { if($(window). scrollTop() + window. innerHeight == $(document). height()) { alert("bottom!"); } });
I haven't used the plugin before but based on the docs at https://github.com/noraesae/perfect-scrollbar
The code you should need is:
$("#message_list").scrollTop( $( "#message_list" ).prop( "scrollHeight" ) );
$("#message_list").perfectScrollbar('update');
The $ selectors may be wrong since I can't see you HTML code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With