1. Web
  2. Web-APIs
  3. DOMMatrixReadOnly
  4. toJSON()

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

DOMMatrixReadOnly: toJSON()-Methode

Baseline Weitgehend verfügbar

Diese Funktion ist gut etabliert und funktioniert auf vielen Geräten und in vielen Browserversionen. Sie ist seit Januar 2020 browserübergreifend verfügbar.

Die toJSON()-Methode der DOMMatrixReadOnly-Schnittstelle erstellt und gibt ein JSON-Objekt zurück. Das JSON-Objekt enthält die 2D-Matrixelemente a bis f, die 16 Elemente der 4X4 3D-Matrix, m[1-4][1-4], die boolesche Eigenschaft is2D und die boolesche Eigenschaft isIdentity.

Syntax

js
toJSON()

Parameter

Keine.

Rückgabewert

Ein JSON-Objekt; eine JSON-Darstellung des DOMMatrixReadOnly-Objekts.

Beispiele

js
const matrix = new DOMMatrixReadOnly();
console.log(matrix.translate(20, 30).toJSON());
/*
{
 "a": 1,
 "b": 0,
 "c": 0,
 "d": 1,
 "e": 20,
 "f": 30,
 "m11": 1,
 "m12": 0,
 "m13": 0,
 "m14": 0,
 "m21": 0,
 "m22": 1,
 "m23": 0,
 "m24": 0,
 "m31": 0,
 "m32": 0,
 "m33": 1,
 "m34": 0,
 "m41": 20,
 "m42": 30,
 "m43": 0,
 "m44": 1,
 "is2D": true,
 "isIdentity": false
}
*/
console.log(matrix.translate(22, 55, 66).toJSON());
/*
{
 "a": 1,
 "b": 0,
 "c": 0,
 "d": 1,
 "e": 22,
 "f": 55,
 "m11": 1,
 "m12": 0,
 "m13": 0,
 "m14": 0,
 "m21": 0,
 "m22": 1,
 "m23": 0,
 "m24": 0,
 "m31": 0,
 "m32": 0,
 "m33": 1,
 "m34": 0,
 "m41": 22,
 "m42": 55,
 "m43": 66,
 "m44": 1,
 "is2D": false,
 "isIdentity": false
}
*/

Spezifikationen

Spezifikation
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-tojson

Browser-Kompatibilität

Siehe auch

Help improve MDN

Erfahren Sie, wie Sie beitragen können Diese Seite wurde automatisch aus dem Englischen übersetzt.

AltStyle によって変換されたページ (->オリジナル) /