Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Perfect Scroll - Set Scrollbar to the Bottom of the Container

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();
like image 623
Jason Biondo Avatar asked Oct 17 '13 04:10

Jason Biondo


People also ask

How do you scroll automatically to the bottom of the page using jQuery?

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.

How do I scroll to the bottom of a scrollable div?

Use element. scroll() to Scroll to Bottom of Div in JavaScript. You can use element. scroll() to scroll to the bottom of an element.

How do I automatically scroll to the bottom of the page?

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.

How can check scroll bottom in jQuery?

scroll(function() { if($(window). scrollTop() + window. innerHeight == $(document). height()) { alert("bottom!"); } });


1 Answers

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.

like image 99
Travis Petrie Avatar answered Oct 13 '22 01:10

Travis Petrie