#app{
width: 300px;
height: 300px;
background-color: red;
}
``<div id="app"></div>
```javascript
const oApp=document.getElementById('app');
oApp.οnmοusemοve=function(){
debounce(()=>{
console.log(1);
})
}
防抖:在指定的时间内移除前边的事件,特点:能够无限延长执行时间
let timer=null
function debounce(callback,delay=1000){
clearTimeout(timer);
timer=setTimeout(()=>{
callback&&callback()
},delay)
}
节流:在指定的时间内移除后边的时间,特点:有节奏的执行事件
function throttle(callback,delay=1000){
if(!timer){
timer=setTimeout(()=>{
callback&&callback();
clearTimeout(timer)
timer=null
},delay)
}
}