DOMMatrixReadOnly:rotate() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

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

DOMMatrixReadOnly 介面的 rotate() 方法返回一個新的 DOMMatrix,該矩陣是透過圍繞源矩陣的每個軸以指定的度數進行旋轉而建立的。原始矩陣不會被更改。

要旋轉時更改矩陣,請參閱 DOMMatrix.rotateSelf()

語法

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

引數

rotX

一個數字;表示旋轉軸的向量的 x 座標。如果非零,則 is2D 為 false。

rotY 可選

一個數字;表示旋轉軸的向量的 y 座標。如果非零,則 is2D 為 false。

rotZ 可選

一個數字;表示旋轉軸的向量的 z 座標。

如果僅傳入 rotX,則 rotX 將用作 z 座標的值,x 座標和 y 座標均設定為零。

返回值

一個 DOMMatrix

示例

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)"

規範

規範
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-rotate

瀏覽器相容性

另見