码迷,mamicode.com
首页 > 其他好文 > 详细

clientHeight ,offsetHeight,style.height,scrollHeight有区别与联系

时间:2015-07-17 15:37:38      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

style.height 包括 元素的滚动条,不包括边框
clientHeight 不包括元素的滚动条和边框,只有在没有元素的滚动条的情况下,style.height相等于clientHeight
offsetHeight 包括元素的滚动条和边框,只有在没有元素的滚动条和边框的情况下,offsetHeight==style.height==clientHeight
scrollHeight offsetHeight+scrollTop,只有在没有元素的滚动条和边框和滚动时的情况下,offsetHeight==style.height==clientHeight==,offsetHeight==style.height==scrollHeight
 公式是:
 style.height=clientHeight+滚动条宽度;
 offsetHeight=style.height+borderTop+borderBottom;
 scrollHeight=offsetHeight+scrollTop;

同理: clientWidth,offsetWidthstyle.width,scrollWidth
演示时营造不同的环境测试(改变eyejs元素的样式)
<div id="eyejs" style="border: solid 10px red;width:100px;height:100px;overflow:scroll;">
<div style="height:200px;"></div>
</div>
<input type="button" onclick="alert(document.getElementById(‘eyejs‘).clientHeight)" value="点击clientHeight" />
<input type="button" onclick="alert(document.getElementById(‘eyejs‘).style.height)" value="点击style.height" />
<input type="button" onclick="alert(document.getElementById(‘eyejs‘).offsetHeight)" value="点击offsetHeight" />
<input type="button" onclick="alert(document.getElementById(‘eyejs‘).scrollHeight)" value="点击scrollHeight" />

clientHeight ,offsetHeight,style.height,scrollHeight有区别与联系

标签:

原文地址:http://www.cnblogs.com/zhwl/p/4654638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!