



理想是火,点燃熄灭的灯。



function moveToBrowserBottom() {
  let timerForDebounce = null; //为了防抖添加的timer
  window.onscroll = function() {
    if (timerForDebounce) clearTimeout(timerForDebounce);
    var scrollTop =
      document.documentElement.scrollTop ||
      window.pageYOffset ||
      document.body.scrollTop;
        // gap是为了计算偏差,有时候会有1px的偏差值
    let gap =
      Math.ceil(document.documentElement.clientHeight + scrollTop) -
      document.documentElement.scrollHeight;  
    if (
      document.documentElement.scrollHeight ===
        Math.ceil(document.documentElement.clientHeight + scrollTop) ||
      gap === 1
    ) {
      timerForDebounce = setTimeout(() => {
        console.log("触底了");
      }, 200);
    }
  };
}
作者: Bill 本文地址: http://biaoblog.cn/info?id=1608281280000
版权声明: 本文为原创文章,版权归 biaoblog 个人博客 所有,欢迎分享本文,转载请保留出处,谢谢!
上一篇:git操作日常记录学习