Scroll up with slimscroll plugin

I used slimScroll on my webpage, content was added by AJAX.

If I scroll down the scrollbar, reload more content (AJAX download), the scrollbar itself always keeps its position as before.

I wonder if the slimScroll function slimScroll any function that I can call to scroll to the top after loading new content?

+8
jquery ajax
source share
4 answers

I don’t think the scroll option described by @rochal will work right now, as it is apparently not being used by the version currently on GitHub . Instead, try scrollTo or scrollBy .

To scroll up:

 $('#elem_id').slimScroll({ scrollTo : '0px' }); 

And vice versa, if you want to scroll down the page, then the following should work:

 var scrollTo_val = $('#elem_id').prop('scrollHeight') + 'px'; $('#elem_id').slimScroll({ scrollTo : scrollTo_val }); 
+21
source share

Starting with version 1.0.0, if you need to scroll up, you can use the build scrollTo command :

$(element).slimScroll({ scrollTo: '0' });

+5
source share

This code works for me.

 var scrollTo_int = $('#elem_id').prop('scrollHeight') + 'px'; $('#elem_id').slimScroll({scrollTo : scrollTo_int }); 

This will take the scroll bar at the bottom position and also take the contents at the bottom of the div.

+2
source share

Alternatively, you can use javascript to solve these problems ...

 document.getElementById("element-id").scrollTop = document.getElementById("element-id").scrollHeight; 

element-id is the id your content area (usually its div ) ..

execute this code when new content is added to your div

0
source share

All Articles