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

View in English Always switch to English

DOMRect.DOMRect()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 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 }

规范

Specification
Geometry Interfaces Module Level 1
# dom-domrect-domrect

浏览器兼容性

更多