简体   繁体   English

如何收听Slimscroll“滚动”事件?

[英]How to listen for Slimscroll “scroll” event?

Basically I want to run some stuff whenever the user scrolls... how could I possibly do that? 基本上我想在用户滚动时运行一些东西......我怎么可能这样做?

I already know about this event which I found on SlimScroll website, but there is no other events other than this one; 我已经知道我在SlimScroll网站上发现的这个事件,但除此之外没有其他事件;

//...

var $scrollable = $('.scrollable');

$scrollable.slimScroll().bind('slimscroll', function (e, pos) {
    // SOME CODE...
});

//...

But this only works when the scrollbar reaches either top or bottom of the scrollable section. 但这仅在滚动条到达可滚动部分的顶部或底部时才有效。

The scrollbar itself works fine, just need an event listener! 滚动条本身工作正常,只需要一个事件监听器!

Thank you 谢谢

OK, after looking into the slimscroll unminified version I spotted this " slimscrolling " event listener, so I simply replaced this with " slimscroll " and things worked as I wanted! 好吧,在查看了slimscroll未经宣传的版本之后,我发现了这个“ slimscrolling ”事件监听器,所以我只是将其替换为“ slimscroll ”并且事情按照我的意愿运行!

So simply run this code; 所以只需运行此代码;

//...

var $scrollable = $('.scrollable');

$scrollable.slimScroll().bind('slimscrolling', function (e, pos) {
    // SOME CODE...
});

//...

Hope this saves your time as I spent ages figuring this out :) Thanks 希望这可以节省你的时间,因为我花了很多时间搞清楚:)谢谢

UPDATE:- 更新: -

For those of you that asked me either privately or here on how you could possibly track the SlimScroll's scroll direction (UP or DOWN)! 对于那些私下或在这里问你如何跟踪SlimScroll的滚动方向(向上或向下)的人!

The bad news is this isn't something that SlimScroll offers as of yet, however on the other side, the good news is I've been able to put together a little snippet that does the job for you! 坏消息是,这不是SlimScroll提供的东西,但另一方面,好消息是我已经能够整理一个为您完成工作的小片段!

[Codepen](https://codepen.io/stylish/pen/KZXeJG?editors=0011)

Hope it helps :) Thanks 希望它有所帮助:)谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM