gpt4 book ai didi

javascript - window.innerWidth window.outerWidth 和有什么区别?

转载 作者:行者123 更新时间:2023-12-02 22:23:56 24 4
gpt4 key购买 nike

我检查了 Firebug 中的 window 对象。 window.innerWidthwindow.outerWidth 均为 1230

这两个值有什么区别?

最佳答案

来自 Mozilla 开发者网络:

window.outerWidth

window.outerWidth gets the width of the outside of the browser window. It represents the width of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.

window.innerWidth

Width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.

表面上这就是他们的工作方式。然而,测试页面显示,无论我在 Ubuntu 12.04 上的 Firefox 14.0.1 中如何调整它们的大小,它们都是相同的。在 Chromium 中,它们返回相差 8 个像素的数字。经过一些航位推算,该特定应用程序上的窗口镶边似乎左侧约为 4 个像素,右侧约为 4 个像素,并且该浏览器已正确识别出这种差异。

我使用的测试页面代码:

<!DOCTYPE html>
<html lang="en">
<head>
<title>12066093</title>
<meta charset="utf-8">
</head>
<body>
<div style="width:2000px; height: 2000px;">hi</div>
<script type="text/javascript">
alert("window.innerWidth: " + window.innerWidth + "\nwindow.outerWidth: " + window.outerWidth);
</script>
</body>
</html>

关于javascript - window.innerWidth window.outerWidth 和有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12066093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com