此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

DOMRect.DOMRect()

基线 广泛可用

自 2020年1月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

DOMRect() 构造函数生成一个新的 DOMRect 对象。

语法

js
var myDOMRect = new DOMRect(x, y, width, height);

参数

x

DOMRect 原点的 x 坐标。

y

DOMRect 原点的 y 坐标。

width

DOMRect 的宽度。

height

DOMRect 的高度。

例子

想生成一个新 DOMRect,你可以运行一行这样的代码:

js
myDOMRect = new DOMRect(0, 0, 100, 100);
// running 'myDOMRect' in the console would then return
// DOMRect { x: 0, y: 0, width: 100, height: 100, top: 0, right: 100, bottom: 100, left: 0 }

规范

规范
Geometry Interfaces Module Level 1
# dom-domrect-domrect

浏览器兼容性

更多