DOMMatrixReadOnly:rotateFromVector() 方法
注意:此功能在 Web Workers 中可用。
DOMMatrixReadOnly 接口的 rotateFromVector() 方法会返回一个新的 DOMMatrix 对象,该对象由源矩阵围绕指定向量与 (1, 0) 之间的角度进行旋转而创建。旋转角度由向量 (1,0)T 与 (x,y)T 之间顺时针方向的角度确定,即 (+/-)arctan(y/x)。如果 x 和 y 都为 0,则角度指定为 0。原始矩阵不会被修改。
要修改矩阵,使其围绕指定向量与 (1, 0) 之间的角度旋转,请参阅 DOMMatrix.rotateFromVectorSelf()。
语法
js
rotateFromVector()
rotateFromVector(rotX)
rotateFromVector(rotX, rotY)
参数
返回值
一个 DOMMatrix。
示例
js
const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.toString()); // original value
// output: "matrix(1, 0, 0, 1, 0, 0)"
console.log(matrix.rotateFromVector().toString()); // defaults to `0`
// output: matrix(1, 0, 0, 1, 0, 0)
console.log(matrix.rotateFromVector(10, 20).toString());
// matrix(0.447, 0.894, -0.894, 0.447, 0, 0)
console.log(matrix.rotateFromVector(-5, 5).toString());
// matrix(-0.707, 0.707, -0.707, -0.707, 0, 0)
console.log(matrix.toString()); // matrix remains unchanged
// output: "matrix(1, 0, 0, 1, 0, 0)"
规范
| 规范 |
|---|
| Geometry Interfaces Module Level 1 # dom-dommatrixreadonly-rotatefromvector |
浏览器兼容性
加载中…
另见
DOMMatrix.rotateFromVectorSelf()DOMMatrixReadOnly.rotate()DOMMatrixReadOnly.rotateAxisAngle()- CSS
transform属性和rotate3d()函数 - CSS
rotate属性 - CSS 变换模块
- SVG
transform属性 CanvasRenderingContext2D接口和rotate()方法