我有一个问题,我想要这样:

$(window).on('mousewheel', function(event) {
  //prevent mousewheel in 1s
  //do something, after 1s, enable mousewheel
}


或像这样:
您在1秒钟内多次滚动滚轮,在事件鼠标滚轮运行1次时起作用。
谁来帮帮我!

最佳答案

您可以执行以下操作:

var mouseWheelEnabled = true;

function doSomethingWithMousewheel(event){
    if(mouseWheelEnabled){
    //... your code here


    // set enabled = false;
    mouseWheelEnabled = false;

    setTimeout(function(){
      mouseWheelEnabled = true;
    }, 1000);
  }

}

$(window).on('mousewheel', doSomethingWithMousewheel);

关于javascript - 防止鼠标滚轮1s后,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56182138/

10-09 17:51