防抖节流实现
1.防抖
function debounce(fun, time) {
let timers;
return function(){
clearTimeout(timers);
let arg = arguments;
timers = setTimeout( () => {
fun.apply(this, arg)
},time)
}
}
2.节流
function throttle(fun,time){
let t1=0 //初始时间
return function(){
let t2=new Date() //当前时间
if(t2-t1>time){
fun.apply(this,arguments)
t1=t2
}
}
}
原文章:https://juejin.cn/post/7016502001911463950

浙公网安备 33010602011771号