2021
09-19
09-19
JavaScript的防抖和节流案例
目录防抖节流:防抖:在一定的时间内只执行最后一次任务;节流:一定的时间内只执行一次;防抖<buttonid="debounce">点我防抖!</button>$('#debounce').on('click',debounce());functiondebounce(){lettimer;//闭包returnfunction(){clearTimeout(timer);timer=setTimeout(()=>{//需要防抖的操作...console.log("防抖成功!");},500);}}节流:...
继续阅读 >