jquery mousewheel:检测车轮何时停止? [英] jquery mousewheel: detecting when the wheel stops?

查看:86
本文介绍了jquery mousewheel:检测车轮何时停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery mousewheel 插件,我想要能够检测何时用户已经完成使用车轮。
类似的功能就像stop:event中的draggable东西。
有人可以指出我正确的方向吗?

I'm using Jquery mousewheel plugin and I would like like to be able to detect when the user has finished using the wheel. Similar functionality as the stop: event in the draggable stuff. Can somebody point me to the right direction?

推荐答案

这里没有停止事件真的 - 你得到一个事件当您执行滚动时,所以每次触发事件都会触发事件触发...当没有任何事情不会发生任何事件,您的处理程序将不会触发。

There's no "stop" event here really - you get an event when you do scroll, so every time a mousewheel event happens the event is triggered...when there's nothing you'll get no events and your handler won't be firing.

您可以检测用户何时在250ms内没有使用,如下所示:

You ca however detect when the user hasn't used it in say 250ms, like this:

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

你可以在这里尝试一下,我们所做的就是使用 $。data() ,如果在该时间用完之前再次使用它,它将被清除...如果不是那么任何代码您想要开火,用户可以使用自己的鼠标滚轮进行任何时间的测试。

You can give it a try here, all we're doing is storing the timeout on each use in using $.data(), if you use it again before that time runs out, it gets cleared...if not then whatever code you wanted to run fires, the user has "finished" using their mousewheel for whatever period of time you're testing for.

这篇关于jquery mousewheel:检测车轮何时停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆