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

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

时间:2015-05-18 06:21:42      阅读:153      评论: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元素的样式)

1 <div id="eyejs" style="border: solid 10px red;width:100px;height:100px;overflow:scroll;">
2 <div style="height:200px;"></div>
3 </div>
4 <input type="button" onclick="alert(document.getElementById(‘eyejs‘).clientHeight)" value="点击clientHeight" />
5 <input type="button" onclick="alert(document.getElementById(‘eyejs‘).style.height)" value="点击style.height" />
6 <input type="button" onclick="alert(document.getElementById(‘eyejs‘).offsetHeight)" value="点击offsetHeight" />
7 <input type="button" onclick="alert(document.getElementById(‘eyejs‘).scrollHeight)" value="点击scrollHeight" />

 

 

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

标签:

原文地址:http://www.cnblogs.com/andywenming/p/4510974.html

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