需要写一个滚动条滑动加载图片的程序,研究了一下onscroll在不同浏览器里的执行次数,分别如下:

var i=0;
E.addHandler(window, 'scroll', function(){
    console.log(i++);
})

firefox

鼠标滚动事件onscroll在firefox/chrome/Ie中执行次数的问题处理

chrome

鼠标滚动事件onscroll在firefox/chrome/Ie中执行次数的问题处理

ie8

鼠标滚动事件onscroll在firefox/chrome/Ie中执行次数的问题处理

总结

滚轮动一下ie执行的次数太多了,需要写个方法,某段时间只执行一次。

var i=0,
    scrollTimer;
E.addHandler(window, 'scroll', function(){
    if(scrollTimer) clearTimeout(scrollTimer);
    scrollTimer = setTimeout(function(){
        console.log(i++);
    }, 200);
})

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案