优化前代码
var i = 0;
window.addEventListener('scroll',function(){
console.log(i++);
},false);
var debounce = null;
window.addEventListener('scroll',function(){
if(debounce){
clearTimeout(debounce);
}
debounce = setTimeout(function(){
console.log("scroll");
},500);
})
本文介绍了一种优化网页滚动事件监听的方法,通过使用防抖技术减少事件处理频率,提高用户体验及浏览器性能。
14万+

被折叠的 条评论
为什么被折叠?



