js监听滚动结束

使用setTimeout模拟滚动结束

let scrollTimer;
document.addEventListener("scroll", () => {
  clearTimeout(scrollTimer);
  scrollTimer = setTimeout(() => {
    // todo something scroll end
  }, 300);
});

如果在滚动进行中,定时任务一直不会被执行,只有滚动停止300毫秒后才会触发

posted @ 2019-12-05 20:28  懒懒同学不懒  阅读(4795)  评论(0编辑  收藏  举报