jquery mousewheel插件:如何每次滚动仅触发一个功能
我正在使用 moushweel 插件,因为我希望我的用户每次向上或向下滚动时都会触发一个操作,但我不想多次触发(如果你有一个苹果魔术鼠标,那就更糟糕了,因为太敏感了)
任何想法怎样预防呢?
这是代码
jQuery(function($) {
$('div.mousewheel_example')
.bind('mousewheel', function(event, delta) {
var dir = delta > 0 ? 'Up' : 'Down',
vel = Math.abs(delta);
$(this).text(dir + ' at a velocity of ' + vel);
return false;
});
});
i'm using a moushweel plugin because i want my user to fire an action everytime it scroll up or down, but i dont want to have multiples fires (if you have a apple magic Mouse it is even worse because is too sensitive)
any idea on how to prevent it?
this is the code
jQuery(function($) {
$('div.mousewheel_example')
.bind('mousewheel', function(event, delta) {
var dir = delta > 0 ? 'Up' : 'Down',
vel = Math.abs(delta);
$(this).text(dir + ' at a velocity of ' + vel);
return false;
});
});
this is the plugin page
http://brandonaaron.net/code/mousewheel/demos
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用 window.setTimeout。也许通过拉出嵌套函数并使用带有计时器的代理函数来实现。示例:
这不会停止事件触发,但会阻止您的函数在每次事件触发时运行。
You could try playing with window.setTimeout. Maybe by pulling out your nested function and using something a proxy function with a timer. Example:
This will not stop the event firing but it will stop your function from running everytime the event fires.
有病,明白了。
如果您正在内部运行动画,只需在其前面添加 .stop()
所以它会读
Sicck, got it.
If you are running an animation inside just preface it with .stop()
So it would read