DOMMatrixReadOnly:rotate() 方法
注意:此功能在 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 |
瀏覽器相容性
載入中…
另見
DOMMatrix.rotateSelf()DOMMatrixReadOnly.rotateAxisAngle()DOMMatrixReadOnly.rotateFromVector()- CSS
transform屬性和rotate3d()函式 - CSS
rotate屬性 - CSS 變換模組
- SVG
transform屬性 CanvasRenderingContext2D介面和rotate()方法