本文實例講述了JS簡單實現滑動加載數據的方法。分享給大家供大家參考,具體如下:
//滑動function getScrollTop(){ var scrollTop = 0; if (document.documentElement && document.documentElement.scrollTop) { scrollTop = document.documentElement.scrollTop; }else if (document.body) { scrollTop = document.body.scrollTop; } return scrollTop;}//獲取當前可視范圍的高度function getClientHeight(){ var clientHeight = 0; if (document.body.clientHeight && document.documentElement.clientHeight) { clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); }else { clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); } return clientHeight;}//獲取文檔完整的高度function getScrollHeight(){ return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);}//綁定事件window.onscroll = function (){ if (getScrollTop() + getClientHeight() == getScrollHeight()) { //dosomething }}
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答