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 } } }
本文来自博客园,作者:lanwf,转载请注明原文链接:https://www.cnblogs.com/lccsdncnblogs/p/16536253.html