DOMRect

草案
本页尚未完工.

一个 DOMRect 代表一个矩形。

DOMRect 表示的盒子的类型由返回它的方法或属性指定。例如,WebVR API 的 VREyeParameters.renderRect 指定了头戴式显示器的一只眼睛应该呈现的影像所在的 canvas 的视口。

它继承自它的父类,DOMRectReadOnly

构造函数

DOMRect()
创建一个新的 DOMRect 对象。

属性

DOMRect 从其父类 DOMRectReadOnly 继承属性。不同之处在于它们不再是只读的。

DOMRectReadOnly.x
DOMRect 原点的 x 坐标。
DOMRectReadOnly.y
DOMRect 原点的 y 坐标。
DOMRectReadOnly.width
DOMRect 的宽度。
DOMRectReadOnly.height
DOMRect 的高度。
DOMRectReadOnly.top
返回 DOMRect 的顶坐标值(与 y 具有相同的值,如果 height 为负值,则为 y + height 的值)。
DOMRectReadOnly.right
返回 DOMRect 的右坐标值(与 x + width 具有相同的值,如果width 为负值,则为 x 的值)。
DOMRectReadOnly.bottom
返回 DOMRect 的底坐标值(与 y + height 具有相同的值,如果 height 为负值,则为 y 的值)。
DOMRectReadOnly.left
返回 DOMRect 的左坐标值(与 x 具有相同的值,如果 width 为负值,则为 x + width 的值)。

方法

DOMRect 从它的父类继承方法,DOMRectReadOnly

静态方法

DOMRectReadOnly.fromRect()
创建一个具有指定位置和尺寸的新 DOMRect 对象。

规范

Specification Status Comment
Geometry Interfaces Module Level 1
DOMRect
Candidate Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
DOMRectChrome Full support 61Edge Full support 79
Full support 79
Full support 12
Alternate Name
Alternate Name Uses the non-standard name: ClientRect
Firefox Full support YesIE No support No
No support No
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: ClientRect
Opera Full support 48Safari Full support 10.1WebView Android Full support 61Chrome Android Full support 61Firefox Android Full support YesOpera Android Full support 45Safari iOS Full support 10.3Samsung Internet Android Full support 8.0
DOMRect() constructorChrome Full support 61Edge Full support 79Firefox Full support 31IE No support NoOpera Full support 48Safari Full support 10.1WebView Android Full support 61Chrome Android Full support 61Firefox Android Full support 31Opera Android Full support 45Safari iOS Full support 10.3Samsung Internet Android Full support 8.0
Available in workersChrome Full support 61Edge Full support 79Firefox Full support 69IE No support NoOpera Full support 48Safari Full support 10.1WebView Android Full support 61Chrome Android Full support 61Firefox Android No support NoOpera Android Full support 45Safari iOS Full support 10.3Samsung Internet Android Full support 8.0

Legend

Full support  
Full support
No support  
No support
Uses a non-standard name.
Uses a non-standard name.

更多