document.body.clientHeight 和 document.documentElement.clientHeight 的区别

来源:互联网 发布:js根据日期计算星期几 编辑:程序博客网 时间:2024/05/23 14:43
document.body.clientHeight ==> BODY对象高度 body 中元素所占的高度。

document.documentElement.clientHeight ==> 可见区域宽度  浏览器窗口的高度


clientHeight

大部分浏览器对 clientHeight 都没有什么异议,都认为是内容可视区域的高度,也就是说页面浏览器中可以看到内容的这个区域的高度,即然是指可看到内容的区域,滚动条不算在内。但要注意padding是算在内。其计算方式为clientHeight = topPadding + bottomPadding+ height - scrollbar.height。

offsetHeight

在IE6,IE7,IE8以及最新的的FF, Chrome中,在元素上都是offsetHeight = clientHeight + 滚动条 + 边框。 

scrollHeight

scrollHeight是元素的padding加元素内容的高度。这个高度与滚动条无关,是内容的实际高度。

计算方式 :scrollHeight = topPadding + bottomPadding + 内容margix box的高度。

在浏览器中的区别在于:

IE6、IE7 认为scrollHeight 是网页内容实际高度,可以小于clientHeight。

FF、Chrome 认为scrollHeight 是网页内容高度,不过最小值是clientHeight。


0 0
原创粉丝点击