1. 程式人生 > >獲取滾動條當前的位置,當前可視範圍的高度,文件完整高度

獲取滾動條當前的位置,當前可視範圍的高度,文件完整高度

(一)獲取滾動條當前的位置/** * 獲取滾動條當前的位置 */ 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); }