本文實例講述了JS簡單實現(xiàn)滑動加載數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:
//滑動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;}//獲取當(dāng)前可視范圍的高度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 }}更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
|
新聞熱點
疑難解答
圖片精選