判断标准:
窗口的高度 + 滚动条的距离 >= 页面的整体高度
1、js
window.addEventListener("scroll",funciton(){
//窗口高度
var windowHeight = document.documentElement.clientHeight|| document.body.clientHeight;
//滚动高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
//页面高度
var documentHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
if(windowHeight + scrollTop == documentHeight){
console.log("页面触底啦")
}
})
2、jquery
$(window).scroll(function(){
// 窗口高度
var windowHeight=$(this).height();
// 滚动高度
var scrollTop=$(this).scrollTop();
// 文档高度
var documentHeight=$(document).height();
if(scrollTop+windowHeight==documentHeight){
alert("到底了!");
}
});