gpt4 book ai didi

jquery鼠标滚轮: detecting when the wheel stops?

转载 作者:行者123 更新时间:2023-12-03 21:45:21 25 4
gpt4 key购买 nike

我正在使用 Jquery mousewheel插件,我希望能够检测用户何时完成使用轮子。与可拖动内容中的 stop: 事件类似的功能。有人能指出我正确的方向吗?

最佳答案

这里确实没有“停止”事件 - 当您滚动时,您会收到一个事件,因此每次发生鼠标滚轮事件时,都会触发该事件...当没有任何内容时,您将不会收到任何消息事件,并且您的处理程序不会被触发。

但是,您可以检测到用户在 250 毫秒内没有使用它,如下所示:

$("#myElem").mousewheel(function() {
clearTimeout($.data(this, 'timer'));
$.data(this, 'timer', setTimeout(function() {
alert("Haven't scrolled in 250ms!");
//do something
}, 250));
});

You can give it a try here ,我们所做的就是存储每次使用 $.data() 时的超时时间,如果您在该时间用完之前再次使用它,它会被清除...如果没有,那么您想要运行的任何代码都会触发,用户已经“完成”了您正在测试的任何时间段内使用鼠标滚轮的操作。

关于jquery鼠标滚轮: detecting when the wheel stops?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3515446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com