jQuery mousewheel插件:如何在每次滚动时仅触发一个功能 [英] jquery mousewheel plugin: how to fire only one function every scroll
问题描述
我使用的是moushweel插件,因为我希望我的用户每次向上或向下滚动时都触发一个动作,但是我不希望多次触发(如果您使用的是Apple Magic Mouse鼠标,那就更糟糕了,因为它太敏感了)
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?
这是代码
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;
});
});
这是插件页面 http://brandonaaron.net/code/mousewheel/demos
推荐答案
您可以尝试使用 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:
var timer;
function proxyFunction(){
clearTimeout(timer);
timer = setTimeout("mouseWheelAction", 1);
}
这不会停止事件触发,但是会在每次事件触发时停止运行您的函数.
This will not stop the event firing but it will stop your function from running everytime the event fires.
这篇关于jQuery mousewheel插件:如何在每次滚动时仅触发一个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!