feat: 补充新项目hx-op
This commit is contained in:
21
hx-op/src/util/debounce.ts
Normal file
21
hx-op/src/util/debounce.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user