原生js滚动条触底

window.onscroll=function(){
  //滚动条上端距离顶部的距离
     var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
     //是可视区的高度
     var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
     //是滚动条的总高度(当前可滚动的页面的总高度)
     var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight;
     //滚动条到底部时触发
     if(scrollTop+windowHeight>=scrollHeight){
         console.log('滚动到底部')
     }
 }

猜你喜欢

转载自blog.csdn.net/weixin_44348028/article/details/108108194