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