网页设计中scrollHeight,offsetHeight,clientHeight在各个浏览器中的区别

5 篇文章 0 订阅
4 篇文章 0 订阅

四大浏览器 chrome,firefox,ie,opera 在网页带滚动条的情况下:

clientHeight在各个浏览器中都是指可见高度

当网页实际内容高度大于clientHeight时,chrome ,firefox,ie,opera 都将scrollHeight和offsetHeight设定为网页内容高度,具体为实际内容高度+滚动条高度+网页边框高度

当网页实际内容高度小于clientHeight时,chrome ,firefox,ie,opera 都将scrollHeight设定为clientHeight,

chrome ,firefox,opera都将offsetHeight设定为网页内容实际高度,具体为实际内容高度 +滚动条高度+网页边框高度,ie11将offsetHeight设定为ClientHeight


<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>


    <style>
        body{
            height: 200px;
        }
       
    </style>
</head>
<body>
<div id="aa">fasdf</div>
<div id="bb">fasdfasd</div>
</body>
<script type="text/javascript">
    var box=document.getElementById("aa");
    alert("scrollHeight is:"+document.documentElement.scrollHeight);
    alert("offsetheight is:"+document.documentElement.offsetHeight);
    alert("clientHeight is :"+document.documentElement.clientHeight);
    alert(document.documentElement.offsetTop);
    alert(document.documentElement.scrollTop);
</script>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值