js debounce

This commit is contained in:
zoujiandong 2023-12-19 13:53:50 +08:00
parent 49af4f2505
commit a36ff7e890

View File

@ -1,10 +1,15 @@
function debounce(fn, delay=800){ function debounce(fn,wait=1500){
let timer = null; var flag = true;
var timer = null;
return function(){ return function(){
clearTimeout(timer); if(flag) {
timer = setTimeout(()=> {
fn.apply(this,arguments); fn.apply(this,arguments);
}, delay) flag = false;
timer = setTimeout(() => {
flag = true
},wait)
} }
} }
}
export default debounce export default debounce