Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll top with slimscroll plugin

Tags:

jquery

ajax

I used slimScroll on my web page with the content is added by AJAX.

If I scroll down the scroll then reload with more content (AJAX load), the scroll bar itself always keep its position the same as before.

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

like image 998
Ichigo Avatar asked Sep 15 '12 21:09

Ichigo


2 Answers

I don't think the scroll option described by @rochal is going to work right now, as it doesn't appear to be used by the version currently up on GitHub. Instead try scrollTo or scrollBy.

To scroll to the top:

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

Conversely, if you want to scroll to the bottom, then the following should work:

var scrollTo_val = $('#elem_id').prop('scrollHeight') + 'px';
$('#elem_id').slimScroll({ scrollTo : scrollTo_val });
like image 178
sheac Avatar answered Sep 17 '22 10:09

sheac


Since version 1.0.0 if you need to scroll to the top you can use build in scrollTo method:

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

like image 24
rochal Avatar answered Sep 17 '22 10:09

rochal