Grsmto / simplebar

Custom scrollbars vanilla javascript library with native scroll, done simple, lightweight, easy to use and cross-browser.
http://grsmto.github.io/simplebar/
MIT License
6.07k stars 533 forks source link

ScrollToPlugin.min.js #130

Closed coisox closed 6 years ago

coisox commented 6 years ago

Hi, kindly help. I want to scroll to anchor. Without simplebar, no problem. So I refer to your sample at https://github.com/Grsmto/simplebar/blob/master/demo/stress-test.html but no luck.

I'm using SimpleBar.js - v2.5.1

Here's my HTML:

<div data-simplebar-direction="vertical" class="x_content">My content here...</div>
<script src="lib/simplebar/TweenMax.min.js"></script>
<script src="lib/simplebar/ScrollToPlugin.min.js"></script>
<script src="lib/simplebar/simplebar.js"></script>

To test the scrolling, I've run all these variation in browser's console:

TweenLite.to($('.x_content'), 0.5, {scrollTo:{y:100}, ease:Power2.easeOut}); No error nothing happen:

TweenLite.to($('.x_content')[0], 0.5, {scrollTo:{y:100}, ease:Power2.easeOut}); No error nothing happen:

TweenLite.to($('.x_content').simplebar('getScrollElement'), 0.5, {scrollTo:{y:100}, ease:Power2.easeOut});

$(...).simplebar is not a function

TweenLite.to($('.x_content')[0].simplebar('getScrollElement'), 0.5, {scrollTo:{y:100}, ease:Power2.easeOut});

$(...)[0].simplebar is not a function

Grsmto commented 6 years ago

@coisox sorry for the late answer, Simplebar is not a "jQuery plugin" anymore since version 2. So this won't work at all the way you wrote. I believe you were referring to the documentation of the version1.

Try this:

var simplebar = new Simplebar($('.x_content')[0]);
TweenLite.to(simplebar.getScrollElement(), 0.5, {scrollTo:{y:100}, ease:Power2.easeOut});