<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
height: 5000px;
background: pink;
}
</style>
</head>
<body>
<div class="box">33</div>
<script>
window.addEventListener('scroll',function(){
// 滚动视口高度(也就是当前元素的真实高度)
let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
// 可见区域高度
let clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// 滚动条顶部到浏览器顶部高度
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
if(clientHeight + scrollTop == scrollHeight){
console.log('滚动条触底了')
}
})
</script>
</body>
</html>
js监听滚动条判断滚动条触底
猜你喜欢
转载自blog.csdn.net/weixin_35958891/article/details/108843364
今日推荐
周排行