DOMMatrixReadOnly: rotate()-Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die rotate()-Methode des DOMMatrixReadOnly-Interfaces gibt eine neue DOMMatrix zurück, die durch das Drehen der Ausgangsmatrix um jede ihrer Achsen um die angegebene Anzahl von Grad erstellt wird. Die ursprüngliche Matrix wird nicht verändert.

Um die Matrix während der Drehung zu ändern, siehe DOMMatrix.rotateSelf().

Syntax

js
DOMMatrixReadOnly.rotate()
DOMMatrixReadOnly.rotate(rotX)
DOMMatrixReadOnly.rotate(rotX, rotY)
DOMMatrixReadOnly.rotate(rotX, rotY, rotZ)

Parameter

rotX

Eine Zahl; die x-Koordinate des Vektors, der die Drehachse angibt. Wenn ungleich null, ist is2D false.

rotY Optional

Eine Zahl; die y-Koordinate des Vektors, der die Drehachse angibt. Wenn ungleich null, ist is2D false.

rotZ Optional

Eine Zahl; die z-Koordinate des Vektors, der die Drehachse angibt.

Wenn nur rotX übergeben wird, dann wird rotX als Wert für die z-Koordinate verwendet und die x- und y-Koordinaten werden beide auf null gesetzt.

Rückgabewert

Eine DOMMatrix.

Beispiele

js
const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.toString());
// output: "matrix(1, 0, 0, 1, 0, 0)"

const rotated = matrix.rotate(30); // rotation and assignment
console.log(matrix.toString()); // original matrix is unchanged
// output: "matrix(1, 0, 0, 1, 0, 0)"
console.log(rotated.toString());
// output: "matrix(0.866, 0.5, -0.5, 0.866, 0, 0)"

Spezifikationen

Specification
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-rotate

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch