//滚动条距离顶部高度
function getScrollTop() {
var scrollTop=0;
if(document.documentElement&&document.documentElement.scrollTop) {
scrollTop=document.documentElement.scrollTop;
}
else if(document.body) {
scrollTop= document.body.scrollTop;
}
return Math.ceil(scrollTop);
}
//滚动条本身高度:就是可视窗口高度
function getScrollBarHeight(){
let scrollBarHeight = document.documentElement.clientHeight;
return Math.ceil(scrollBarHeight);
}
//整个页面高度
function getPageHeight() {
return Math.ceil(Math.max(document.body.clientHeight,document.documentElement.scrollHeight));
}
window.onscroll = function () {
let top = getScrollTop();
let ch = getScrollBarHeight();
let sh = getPageHeight();
if (top + ch >= sh) {
console.log("到达底部");
}else{
console.log("没有到达底部");
}
}
判断浏览器滚动到底部
最新推荐文章于 2024-04-18 14:34:31 发布