DOMRectReadOnly: toJSON() 方法
注意:此功能在 Web Workers 中可用。
DOMRectReadOnly 介面的 toJSON() 方法返回 DOMRectReadOnly 物件的 JSON 表示。
語法
js
toJSON()
引數
無。
返回值
一個新物件,其屬性值設定為呼叫該方法的 DOMRectReadOnly 物件中的值。
示例
此示例建立一個 DOMRectReadOnly 物件,表示一個位於 (10, 20) 位置,寬度為 100,高度為 50 的矩形。然後呼叫 toJSON() 方法來獲取該矩形的 JSON 表示。
js
const rect = new DOMRectReadOnly(10, 20, 100, 50);
const rectJSON = rect.toJSON();
console.log(rectJSON);
// Output: { x: 10, y: 20, width: 100, height: 50, top: 20, right: 110, bottom: 70, left: 10 }
規範
| 規範 |
|---|
| Geometry Interfaces Module Level 1 # dom-domrectreadonly-tojson |
瀏覽器相容性
載入中…