js debounce
This commit is contained in:
parent
49af4f2505
commit
a36ff7e890
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user