You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

21 lines
582 B

export function debounce(_this: any, fn: (arg0: any) => void) {
// 用rAF去做防抖
return function (...args: any) {
if (_this.lock) return;
const run = function () {
// requestIdleCallback-任务调度
window.requestIdleCallback(function (deadline) {
_this.lock = true;
// 判断空闲时间
// 显示器刷新频率HZ 16.7ms内不会重复执行
if (deadline.timeRemaining() > 1000 / 60) {
fn(...args);
_this.lock = false;
} else {
run();
}
});
};
run();
};
}