Window.innerWidth - Web APIs 编辑
The read-only Window
property innerWidth
returns the interior width of the window in pixels. This includes the width of the vertical scroll bar, if one is present.
More precisely, innerWidth
returns the width of the window's layout viewport. The interior height of the window—the height of the layout viewport—can be obtained from the innerHeight
property.
Syntax
let intViewportWidth = window.innerWidth;
Value
An integer value indicating the width of the window's layout viewport in pixels. This property is read-only, and has no default value.
To change the window's width, use one of the Window
methods for resizing windows, such as resizeBy()
or resizeTo()
.
Usage notes
If you need to obtain the width of the window minus the scrollbar and borders, use the root <html>
element's clientWidth
property instead.
The innerWidth
property is available on any window or object that behaves like a window, such as a frame or tab.
Example
// This will return the width of the viewport
var intFrameWidth = window.innerWidth;
// This will return the width of the frame viewport within a frameset
var intFrameWidth = self.innerWidth;
// This will return the width of the viewport of the closest frameset
var intFramesetWidth = parent.innerWidth;
// This will return the width of the viewport of the outermost frameset
var intOuterFramesetWidth = top.innerWidth;
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'window.innerWidth' in that specification. | Working Draft | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论