常用于页面缩放、滚动事件、鼠标移动事件节流处理
const delayFnO: { [x: string]: any } = {};
function delayTimeOut(key: string, time: number) {
if (!time) return;
setTimeout(() => {
if (delayFnO[key]) delayFnO[key]();
if (delayFnO[key]) {
delete delayFnO[key];
delayTimeOut(key, time);
}
}, time);
delayFnO[key] = () => {
delete delayFnO[key];
};
}
export function delayFn(key: string, fn: any, time = 200) {
if (delayFnO[key]) {
delayFnO[key] = fn;
return;
}
delayTimeOut(key, time);
fn();
}
标签:一次,string,delayFnO,单位,key,time,delayTimeOut,执行,fn
From: https://www.cnblogs.com/dkf717/p/17600966.html