實例如下所示:
//獲取滾動條距離頂部位置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);}//判斷滾動條是否達到底部getScrollTop() + getClientHeight() == getScrollHeight()以上這篇基于滾動條位置判斷的簡單實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答