Javascript 中的去抖动不适用于 wheel 事件

Debouncing in Javascript not working with wheel event

我正在尝试使用去抖功能来限制调用的滚动事件的数量。

我不确定为什么这根本不起作用...

有什么想法吗?

window.addEventListener('wheel', () => {
  debounce(scrollSection, 300);
});

const scrollSection = () => {
  console.log(1);
}

const debounce = function(fn, d) {
  let timer;
  return function() {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(context, args);
    }, d);
  }
}

它在每个 wheel 事件上创建去抖函数。先debounce一个函数,再放入事件监听器

window.addEventListener('wheel', debounce(scrollSection, 300));

const scrollSection = () => {
  console.log(1);
}

const debounce = function(fn, d) {
  let timer;
  return function() {
    let context = this;
    let args = arguments;
    clearTimeout(timer);
    timer = setTimeout(() => {
      fn.apply(context, args);
    }, d);
  }
}