JavaScript: 避免事件重复触发

js性能优化

Posted by chanweiyan on October 2, 2020

避免事件重复触发

1
2
3
4
5
// 每次事件触发后,先清除之前的事件,再继续执行
floor.$win.on('scroll resize', floor.showFloor = function() {
  clearTimeout(floor.floorTimer);
  floor.floorTimer = setTimeout(floor.timeToShow, 250);
})

参考

  • https://class.imooc.com/lesson/807#mid=20292