DOMQuad:toJSON() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

注意:此功能在 Web Workers 中可用。

DOMQuad 方法 toJSON() 返回 DOMQuad 对象的 JSON 表示。

语法

js
toJSON()

参数

无。

返回值

一个新的对象,其属性值设置为调用该方法的 DOMQuad 中的值。

示例

此示例创建一个 DOMQuad,其中包含四个表示当前窗口角的 DOMPoint 对象(使用屏幕坐标),然后将其转换为 JSON。

js
const topLeft = new DOMPoint(window.screenX, window.screenY);
const topRight = new DOMPoint(
  window.screenX + window.innerWidth,
  window.screenY,
);
const bottomLeft = new DOMPoint(
  window.screenX,
  window.screenY + window.innerHeight,
);
const bottomRight = new DOMPoint(
  window.screenX + window.innerWidth,
  window.screenY + window.innerHeight,
);

const quad = new DOMQuad(topLeft, topRight, bottomRight, bottomLeft);

const quadJSON = quad.toJSON();

规范

规范
Geometry Interfaces Module Level 1
# dom-domquad-tojson

浏览器兼容性