58

防抖、节流 | Shawnchen / XMU 。

 6 years ago
source link: http://alloween.top/2018/04/16/%E9%98%B2%E6%8A%96%E3%80%81%E8%8A%82%E6%B5%81/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
浏览器的 resize、scroll、keypress、mousemove 等事件在触发时,会不断地调用绑定在事件上的回调函数,极大地浪费资源,降低前端性能。为了优化体验,需要对这类事件进行调用次数的限制。防抖(debounce)作用是在短时间内多次触发同一个函数,只执行最后一次,或者只在开始时执行。以用户拖拽改变窗口大小,触发 resize 事件为例,在这过程中窗口的大小一直在改变,所以如果

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK