【问题标题】:jquery mousewheel plugin: how to fire only one function every scrolljquery mousewheel插件:如何每次滚动只触发一个功能
【发布时间】:2011-01-04 16:52:56
【问题描述】:

我正在使用 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;
        });
});

这是插件页面 http://brandonaaron.net/code/mousewheel/demos

【问题讨论】:

    标签: jquery mousewheel


    【解决方案1】:

    你可以试试window.setTimeout。也许通过拉出嵌套函数并使用带有计时器的代理函数。示例:

    var timer; 
    
    function proxyFunction(){
      clearTimeout(timer);
      timer = setTimeout("mouseWheelAction", 1);
    }
    

    这不会停止事件触发,但会阻止您的函数在每次事件触发时运行。

    【讨论】:

      【解决方案2】:

      病了,明白了。 如果你在里面运行动画,只需在它前面加上 .stop() 所以它会读

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

      【讨论】:

        猜你喜欢
        • 2013-10-08
        • 1970-01-01
        • 2012-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-26
        • 1970-01-01
        • 2016-04-21
        相关资源
        最近更新 更多