const handle = ()=>{
let docEle = document.documentElement;
let contentHeight = docEle.scrollHeight; //获取网页内容所占的高度
// window.innerHeight 获取窗口的可见高度
// docEle.scrollTop获取垂直滚动偏移量
if(contentHeight - docEle.scrollTop == window.innerHeight){
//当滚动条到底时,docEle.scrollTop + window.innerHeight 跟contentHeight相等
console.log('触底')
}
}
//监听window的滚动事件
window.addEventListener('scroll', handle);
网友评论