我正在嘗試使用 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); }}
Javascript 中的去抖動不適用于滾輪事件
繁花不似錦
2021-11-18 17:20:12