clientHeight offsetHeight scrollHeight

来源:互联网 发布:热处理工艺模拟软件 编辑:程序博客网 时间:2024/06/05 16:43

参考文章: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无关。





0 0