<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>Document</title>
<style?type="text/css">
*{
padding:?0;
margin:?0;
}
.box{
width:?200px;
height:?200px;
border:?10px?solid?blue;
padding:?10px;
overflow:?auto;
}
.inner{
width:?300px;
height:?300px;
}
</style>
</head>
<body>
<div?id="box"?class="box"><div?class="inner"></div></div>
<script>
console.log(box.scrollWidth);
console.log(box.scrollHeight);
</script>
</body>
</html>為何寬度計算,比高度要少算10px。
2 回答

weibo_哆啦A夢有大口袋_0
TA貢獻107條經驗 獲得超146個贊
5.scrollWidth和scrollHeight
document.body的scrollWidth和scrollHeight與div的scrollWidth和
scrollHeight是有點區別的。
1.給定寬高小于瀏覽器窗口
scrollWidth通常是瀏覽器窗口的寬度
scrollHeight通常是瀏覽器窗口的高度
2.給定寬高大于瀏覽器窗口,且內容小于給定寬高
scrollWidth給定的寬度+其所有的padding、margin和border
scrollHeight給定的高度+其所有的padding、margin和border
- 2 回答
- 0 關注
- 1580 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消