clientHeight offsetHeight scrollHeight

參考文章:http://blog.csdn.net/magic232/article/details/20443839

clientHeight

大部分瀏覽器對 clientHeight 都沒有什麼異議,都認爲是內容可視區域的高度,也就是說頁面瀏覽器中可以看到內容的這個區域的高度,即然是指可看到內容的區域,滾動條不算在內。但要注意padding是算在內。其計算方式爲clientHeight = topPadding + bottomPadding+ height - scrollbar.height。


offsetHeight

在IE6,IE7,IE8以及最新的的FF, Chrome中,在元素上都是offsetHeight = clientHeight + 滾動條 + 邊框。 


scrollHeight

scrollHeight是元素的padding加元素內容的高度。這個高度與滾動條無關,是內容的實際高度。

計算方式 :scrollHeight = topPadding + bottomPadding + 內容 box的高度。

這裏的scrollHeight的計算方式是基於內層元素的box定義的高度小於外層元素的height得到的,而內容box指的是子元素的box,包括margin,padding,border和height

最新的主流瀏覽器都認爲scrollHeight的最小高度爲clientHeight。

如果內層元素的box定義的高度大於外層元素的height,則分成下面兩種情況:

一是overflow爲scroll或者hidden,scrollHeight=topPaffinh+內容box的高度

二是overflow爲visible或未定義overflow,可以設置三個嵌套div驗證。


注:對於documentElement來說,offsetHeight爲body的offsetHeight+margin,而與documentElement的clientHeight無關。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章