js 检测滚动事件


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>标题</title>
</head>

<body>
    <header>
    </header>
    <section style="height: 1500px;background-color: #f0f0f0">
    </section>
    <footer>
    </footer>
</body>
</html>
1     window.onscroll = function () {
2 
3         var a = document.documentElement.scrollTop || document.body.scrollTop;//滚动条y轴上的距离
4         var b = document.documentElement.clientHeight || document.body.clientHeight;//可视区域的高度
5         var c = document.documentElement.scrollHeight || document.body.scrollHeight;//可视化的高度与溢出的距离(总高度)
6         if(a + b == c){
7             alert('已滚动到底部!')
8         }
9     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM