js实现滚动条到底分页
作者:互联网
js滚动分页代码
function getScrollTop() { var scrollPos; if (window.pageYOffset) { scrollPos = window.pageYOffset; } else if (document.compatMode && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; } else if (document.body) { scrollPos = document.body.scrollTop; } return scrollPos; }
window.onscroll = function () {
//距离顶部的高度 let scrollPos = getScrollTop(); if(scrollPos > 0) {
//总高度-客户端高度-距离顶部高度 = 0 表示已经下拉到底了,即实现分页逻辑 if (document.body.scrollHeight - document.body.clientHeight - scrollPos === 0) { //你的分页代码TODO } } }
标签:body,分页,高度,js,滚动条,window,document,scrollPos 来源: https://www.cnblogs.com/lccsdncnblogs/p/16536253.html