【HTML/CSS】主流浏览器下下offsetHeight\clientHeight\scrollHeight以及window的innerHeight\outerHeight等的关系

1、Firefox32.03

body
clientHeight:body.padding+ body.height(css设置或内容撑的,以设置的优先);

offsetHeight:body.padding+ body.height(css设置或内容撑的,以设置的优先)+body.border;

scrollHeight:body.padding+ body.height(css设置或内容撑的,谁大谁优先);


documentElement
clientHeight= window.innerHeight -scrollbar.width。

offsetHeight= body.padding+ body.height(css设置或内容撑的,以设置的优先)+body.border + body.margin。

scrollHeight=body.padding+ body.height(css设置或内容撑的,谁大谁优先)+body.border + body.margin,但最小值是documentElement.clientHeight。


说明:

a、设置的优先指的是如果有明确设置body的高度则忽略内容高度

b、可以针对上面的六项属性中的每一项可以依次从下面的三组数据中进行对比来证明



设置的body以及内部元素的样式数据为

<style>

html,body,div{

margin:0;

padding:0;

border:none;

}

</style>


第一组数据

<body style="border:1px solid; height:100px;padding-top:10px;margin-top:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

结果为:

window.screen.height:614
window.outerHeight:460
window.innerHeight:336
body scrollHeight:1010
body offsetHeight:112
body clientHeight:110
documentElment scrollHeight:1061
documentElment offsetHeight:162
documentElment clientHeight:319

第二组数据:

<body style="border:1px solid; height:100px;padding:10px;margin:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

结果为:

window.screen.height:614
window.outerHeight:460
window.innerHeight:336
body scrollHeight:1010
body offsetHeight:122
body clientHeight:120
documentElment scrollHeight:1061
documentElment offsetHeight:222
documentElment clientHeight:319

第三组数据:

<body style="border:1px solid; height:1000px;padding-top:10px;margin-top:50px;">
<div style="height:100px; width:800px;"></div>
</body>

window.screen.height:614
window.outerHeight:460
window.innerHeight:336
body scrollHeight:1010
body offsetHeight:1012
body clientHeight:1010
documentElment scrollHeight:1062
documentElment offsetHeight:1062
documentElment clientHeight:319

2、chrome36.0.1985.125

body
clientHeight= body.padding + body.height(css设置或内容撑大,设置优先);

offsetHeight =body.padding + body.height(css设置或内容撑大,设置优先)+ body.border;

scrollHeight=body.padding+ body.height(css设置或内容撑的,谁大谁优先)+body.border+body.margin。

documentElement
clientHeight= window.innerHeight。

offsetHeight  = body.padding + body.height(css设置或内容撑大,设置优先)+ body.border+ body.margin;

scrollHeight  =body.padding+ body.height(css设置或内容撑的,谁大谁优先)+body.border + body.margin,但最小值是documentElement.offsetHeight。


第一组数据:

<body style="border:1px solid;height:100px;padding-top:10px;margin-top:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

window.screen.height:768
window.outerHeight:734
window.innerHeight:619
body scrollHeight:1061
body offsetHeight:112
body clientHeight:110
documentElment scrollHeight:1061
documentElment offsetHeight:162
documentElment clientHeight:619


第二组数据:

<body style="border:1px solid; height:100px;padding:10px;margin:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

window.screen.height:768
window.outerHeight:734
window.innerHeight:619
body scrollHeight:1061
body offsetHeight:122
body clientHeight:120
documentElment scrollHeight:1061
documentElment offsetHeight:222
documentElment clientHeight:619


第三组数据:

<body style="border:1px solid; height:1000px;padding-top:10px;margin-top:50px;">
<div style="height:100px; width:800px;"></div>
</body>

window.screen.height:768
window.outerHeight:734
window.innerHeight:619
body scrollHeight:1062
body offsetHeight:1012
body clientHeight:1010
documentElment scrollHeight:1062
documentElment offsetHeight:1062
documentElment clientHeight:619


3、IE11

body
clientHeight= body.padding + body.height(css设置或内容撑大,设置优先)

offsetHeight = body.padding + body.height(css设置或内容撑大,设置优先)+ body.border

scrollHeight =body.padding + body.height(css设置或内容撑大,谁大谁优先),但最小值是clientHeight。

documentElement
clientHeight =window.innerHeight-scrollbar.height

offsetHeight = body.padding + body.height(css设置或内容撑大,设置优先)+ body.border+body.margin

scrollHeight=body.padding + body.height(css设置或内容撑大,谁大谁优先)+ body.border+body.margin,但最小值是body.offsetHeight+ margin。


第一组数据:

<body style="border:1px solid;height:100px;padding-top:10px;margin-top:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

window.screen.height:614
window.outerHeight:448
window.innerHeight:364
body scrollHeight:1010
body offsetHeight:112
body clientHeight:110
documentElment scrollHeight:1061
documentElment offsetHeight:162
documentElment clientHeight:347



第二组数据:

<body style="border:1px solid; height:100px;padding:10px;margin:50px;">
<div style="height:1000px; width:800px;"></div>
</body>

window.screen.height:614
window.outerHeight:448
window.innerHeight:364
body scrollHeight:1010
body offsetHeight:122
body clientHeight:120
documentElment scrollHeight:1061
documentElment offsetHeight:222
documentElment clientHeight:347


第三组数据:

<body style="border:1px solid; height:1000px;padding-top:10px;margin-top:50px;">
<div style="height:100px; width:800px;"></div>
</body>

window.screen.height:614
window.outerHeight:448
window.innerHeight:364
body scrollHeight:1010
body offsetHeight:1012
body clientHeight:1010
documentElment scrollHeight:1062
documentElment offsetHeight:1062
documentElment clientHeight:347


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值