function throttle(fn, delay) {
let timer = null;
let startTime = Date.now();
return function() {
let curTime = Date.now();
let remainning = delay - (curTime - startTime);
const ctx = this;
let args = arguments;
clearTimeout(timer);
if (remainning <= 0) {
fn.applay(ctx, args);
startTime = Date.now()
} else {
timer = setTimeout(fn, remainning)
}
}
}
js throttle
最新推荐文章于 2024-08-22 14:32:34 发布