编辑代码

window.addEventListener('scroll', (e) => {
  // 获取窗口的可视高度(不包含滚动条)
  let clientHeight = window.clientHeight || document.body.clientHeight || document.documentElement.clientHeight
  // 获取滚动条距离顶部的位置
  let scrollTop = window.screenTop || document.body.scrollTop || document.documentElement.scrollTop
  // 获取文档内容的实际高度(包含滚动条,padding)
  let scrollHeight = window.scrollHeight || document.body.scrollHeight || document.documentElement.scrollHeight

  // 获取滚动条距离底部的高度
  let scrollBottomHeight = scrollHeight - scrollTop - clientHeight
  console.log('底部距离====>', Math.ceil(scrollBottomHeight));
})