js debounce
This commit is contained in:
parent
49af4f2505
commit
a36ff7e890
@ -1,10 +1,15 @@
|
||||
function debounce(fn, delay=800){
|
||||
let timer = null;
|
||||
return function(){
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(()=> {
|
||||
fn.apply(this, arguments);
|
||||
}, delay)
|
||||
}
|
||||
function debounce(fn,wait=1500){
|
||||
var flag = true;
|
||||
var timer = null;
|
||||
return function(){
|
||||
if(flag) {
|
||||
fn.apply(this,arguments);
|
||||
flag = false;
|
||||
timer = setTimeout(() => {
|
||||
flag = true
|
||||
},wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default debounce
|
||||
Loading…
x
Reference in New Issue
Block a user