Javascript 鼠标滚轮事件太快。如何禁用它

Javascript 鼠标滚轮事件太快。如何禁用它,javascript,jquery,mousewheel,Javascript,Jquery,Mousewheel,我试图在我的网站udowalzfinal.umatechcorner.com中引入类似hugeinc.com的效果 我做了以下几件事 $(window).on({ 'DOMMouseScroll mousewheel': ScrollBegin }); var delta = 0; var scrollThreshold = 10; function ScrollBegin(e) { // --- Scrolling up --- if (e.ori

我试图在我的网站udowalzfinal.umatechcorner.com中引入类似hugeinc.com的效果

我做了以下几件事

$(window).on({
'DOMMouseScroll mousewheel': ScrollBegin
});

var delta = 0;
var scrollThreshold = 10;

        function ScrollBegin(e) {

        // --- Scrolling up ---
    if (e.originalEvent.detail < 0 || e.originalEvent.wheelDelta > 0) { 
        delta--;
                    console.log(delta);
        if ( Math.abs(delta) >= scrollThreshold) {
         timer = setTimeout(function () {
                    MoveScreen('up');                        
                }, 800);
        clearTimeout(timer);
    }
}

// --- Scrolling down ---
else {

    delta++;
 console.log(delta); 
    if (delta >= scrollThreshold) {
     timer = setTimeout(function () {
                    MoveScreen('down');
                    clearTimeout(timer);

                }, 800);
    }
}

// Prevent page from scrolling
return false;    
        }
$(窗口)。打开({
“滚动鼠标滚轮”:滚动开始
});
var-delta=0;
风险值阈值=10;
功能滚动开始(e){
//---向上滚动---
如果(e.originalEvent.detail<0 | | e.originalEvent.wheelDelta>0){
三角洲--;
控制台日志(增量);
if(数学绝对值(增量)>=scrollThreshold){
定时器=设置超时(函数(){
移动屏幕(“向上”);
}, 800);
清除超时(计时器);
}
}
//---向下滚动---
否则{
delta++;
控制台日志(增量);
如果(增量>=滚动阈值){
定时器=设置超时(函数(){
移动屏幕(“向下”);
清除超时(计时器);
}, 800);
}
}
//防止页面滚动
返回false;
}
我不知道该为scrollThreshold设置什么值

引发鼠标滚轮事件并执行ScrollBegin。但这在IE中太慢了&在使用苹果鼠标的Safari中太快了

每次鼠标滚轮移动都会引发鼠标滚轮事件。在我的例子中,当我滚动鼠标滚轮一次时,它会引发事件10次。如何禁用这9个事件并只处理一次

这篇文章并不能解决我的问题。这只支持向上移动一次&然后向下移动一次。但我的页面上有5张幻灯片


有人能帮忙吗?

您想看看类似下划线.js的去盎司函数。您可以通过在页面上添加下划线直接使用debounce(这不是一个坏主意),也可以自己实现。还有油门,工作原理稍有不同;以下是两种情况的示例:


您可能应该使用
去Bouncer

//Debouncer functions add a delay between an event and a reaction, so scaling and scrolling don't evoke a function dozens of times.
function debouncer(func, timeout) {
    var timeoutID , timeout = timeout || 200;
    return function () {
        var scope = this , args = arguments;
        clearTimeout( timeoutID );
        timeoutID = setTimeout( function () {
            func.apply( scope , Array.prototype.slice.call( args ) );
        } , timeout );
    };
}
这是一个通用函数。像这样使用它:

jQuery(window).scroll(debouncer(function(){
    //Call your scroll handler here.
}));
要真正微调延迟,请添加cecond参数,如:

jQuery(window).scroll(debouncer(function(){
    //Call your scroll handler here.
}), 600);

也请访问Hi Rachel,感谢您提供的URL。nicescroll不适合我的情况,因为我想显示幻灯片之类的内容。另一个链接也没有什么帮助。我只是想试试。如果您正在查找库示例,请访问我的库,我宁愿执行
setTimeout(fn.apply.bind(fn,this,argsCopy),interval)谢谢。这太完美了。我对我的代码做了一点修改,一切都很好@Paul。谢谢