- 去抖
// 去抖
var Debouncing = (function(){
var t = null;
return function(fn , delay){
if(t==null){
t = setTimeout( ()=>{
t = null
} , delay)
fn()
}
}
})()
- 节流
// 节流
var Throttling = (function(){
var t = null;
return function(fn , delay){
clearTimeout(t);
t = setTimeout( () => {
fn()
} , delay )
}
})()
调用
document.onmouseover = function(){
Throttling(()=>{
console.log("节流中...")
} , 500)
}