<!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 }