页面位置 top、postop、scrolltop、offsetTop、scrollHeight、offsetHeigh

2020-05-10 11:39:03易采站长站整理

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

对某个HTML控件

offsetHeight是自身元素的高度,scrollHeight是 自身元素的高度+隐藏元素的高度。


<div id=”container” style=”background-color:silver; width:100px; height:100px; overflow:auto;”>
<p style=”background-color:red; height:250px; “>
别再做情人 做只猫 做只狗 不做情人 做只宠物至少可爱迷人 和你相交不浅无谓明日会被你憎</p>
</div>
<script type=”text/javascript”><!–
alert(container.offsetHeight);
alert(container.scrollHeight);
// –></script>

将依次输出100,250。因为已经指定了元素的height为100px,所以offsetHeight始终为100px;内部元素为250px,而容器元素只有100px,那么还有150px的内容它无法显示出来,但它却是实际存在的,所以scrollHeight值为100+150=250。