function scrollBottomOrTop() {
var clients = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// 瀏覽器的可視高度,兼容處理
var scrollTop = document.body.scrollTop; //滾上去的高度
var wholeHeight = document.body.scrollHeight; //整個(gè)頁(yè)面的高度
if(clients + scrollTop >= wholeHeight){
alert('我已經(jīng)滾動(dòng)到了底部啊楚!');
}
if(scrollTop == 0){
alert('我已經(jīng)滾動(dòng)到了頂部!')
}
}
window.onscroll = scrollBottomOrTop; //在滾動(dòng)滾動(dòng)條的時(shí)候調(diào)用這個(gè)方法浑彰;
這是判斷網(wǎng)頁(yè)是否滾動(dòng)到底部恭理,可以用到加載更多這樣的實(shí)際案例中,譬如上述中郭变,在
if(clients + scrollTop >= wholeHeight){ ... // 在這里寫(xiě)一些Ajax請(qǐng)求 }```