window属性:innerWidth

2018-04-10 10:41 更新

innerWidth属性

浏览器窗口 viewport 的宽度(以像素为单位),包括(如果呈现的话)垂直滚动条。

注意:如果您用 nsIDOMWindowUtils.setCSSViewport() 为页面布局设置虚拟窗口大小,则此属性返回的值与使用该方法设置的视口宽度相对应。

innerWidth属性语法

var intViewportWidth = window.innerWidth;

innerWidth属性值

intViewportWidth 存储 window.innerWidth 属性值。

该 window.innerWidth 属性是只读的;它没有默认值。

笔记

该 innerWidth 属性在任何 window 对象(如window,frame,frameset 或辅助窗口)中都受支持。

有一种算法可以获取视口的宽度,但不包括(如果呈现的话)垂直滚动条。

innerWidth属性示例

// 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;

要更改窗口的大小,请参阅 window.resizeBy 和 window.resizeTo。

规范

规范状态注释
CSS对象模型(CSSOM)视图模块
该规范中'window.innerWidth'的定义。
Working Draft
初始定义

浏览器兼容性

我们正在将兼容性数据转换为机器可读的JSON格式。

  • 电脑端
特征Chrome
Edge
Firefox(Gecko)
Internet Explorer
Opera
Safari
基本支持支持:1支持支持:1.0(1.7或更早版本)[1]支持:9支持:9支持:3
  • 移动端

特征AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基本支持支持:1支持支持:1.0 [1]支持:9支持:9支持:3

注释:

[1]从Firefox 4到24,该 innerWidth 属性有问题,并且在某些情况下页面加载之前可能会给出错误的值,请参阅错误641188

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号