开发者

jquery mousewheel plugin: how to fire only one function every scroll

开发者 https://www.devze.com 2023-02-03 00:26 出处:网络
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

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);
         开发者_StackOverflow   return false;
        });
});

this is the plugin page http://brandonaaron.net/code/mousewheel/demos


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.


Sicck, got it. If you are running an animation inside just preface it with .stop() So it would read

$('#findme').stop().animate(...);
0

精彩评论

暂无评论...
验证码 换一张
取 消