防抖
//捕获最后一次执行
let inp = document.querySelector('input');
let t = null;
inp.oninput = function(){
if(t !== null){
clearTimeout(t);
}
t = setTimeout(()=>{
console.log(this.value);
},500)
}
节流
//控制执行次数,不会不停的刷新
let flag = true;
window.onscroll = function(){
if(flag){
setTimeout(()=>{
console.log("反应");
flag = true;
},1000)
}
flag = false;
}