关于获取屏幕各个高度

179 阅读1分钟
window.addEventListener('scroll', addScroll)

function addScroll() {
  const advertising = document.querySelector('.download')

  //scrollTop是滚动条滚动时,距离顶部的距离
  //为了保证兼容性,这里取两个值,哪个有值取哪一个
  let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  //windowHeight是可视区的高度
  let windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
  //scrollHeight是滚动条的总高度
  let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
  // footer 高度
  let footerHeight = document.querySelector('.footer').clientHeight

  //滚动条到底部的条件
  if ((scrollTop + windowHeight) >= scrollHeight - footerHeight) {
    //到了这个就可以进行业务逻辑加载后台数据了
 
}