function scrollBottomOrTop() {
var clients = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// 瀏覽器的可視高度,兼容處理
var scrollTop = document.body.scrollTop; //滾上去的高度
var wholeHeight = document.body.scrollHeight; //整個頁面的高度
if(clients + scrollTop >= wholeHeight){
alert('我已經滾動到了底部!');
}
if(scrollTop == 0){
alert('我已經滾動到了頂部!')
}
}
window.onscroll = scrollBottomOrTop; //在滾動滾動條的時候調用這個方法;
這是判斷網頁是否滾動到底部,可以用到加載更多這樣的實際案例中,譬如上述中,在
if(clients + scrollTop >= wholeHeight){ ... // 在這里寫一些Ajax請求 }```