1. 程式人生 > >$(document).height()、$(document).scrollTop()

$(document).height()、$(document).scrollTop()

當前 scrolltop 高度 left 水平滾動 scrollto adding 註意 需要

(document).height()、$(document).scrollTop():

jQuery(window).height()代表了當前可見區域的大小,而jQuery(document).height()則代表了整個文檔的高度,可視具體情況使用.

註意當瀏覽器窗口大小改變時(如最大化或拉大窗口後) jQuery(window).height() 隨之改變jQuery(document).height()是不變的。

$(document).scrollTop() 獲取垂直滾動的距離 即當前滾動的地方的窗口頂端到整個頁面頂端的距離。

$(document).scrollLeft() 這是獲取水平滾動條的距離。

要獲取頂端 ,只需要獲取到scrollTop()==0的時候 就是頂端了。

要獲取底端 ,只要獲取scrollTop()>=(document).height()?(window).height() 就可以知道已經滾動到底端了。

height:指元素內容的高度 ,jQuery中的height()方法返回的就是這個高度。
clientHeight:內容高度+padding高度 ,jQuery中的innerHeight()方法返回的就是這個高度。
offsetHeight:內容高度+padding高度+邊框寬度 ,jQuery中的outerHeight()方法返回的就是這個高度。

$(document).height()、$(document).scrollTop()