DOMMatrixReadOnly:multiply() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

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

DOMMatrixReadOnly 接口的 multiply() 方法创建并返回一个新矩阵,该矩阵是当前矩阵与 otherMatrix 参数的点积。如果省略 otherMatrix,则当前矩阵将与一个矩阵相乘,该矩阵中除了右下角及其左上角的元素之外,所有元素均为 0。这些元素(m33m34)的默认值为 1。原始矩阵不会被修改。

要在相乘时修改矩阵,请参阅 DOMMatrix.multiplySelf()

语法

js
multiply()
multiply(otherMatrix)

参数

otherMatrix 可选

DOMMatrix 乘数。

返回值

一个 DOMMatrix

示例

js
const matrix = new DOMMatrixReadOnly().translate(13, 21);
const multipliedMatrix = matrix.multiply(matrix);
console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 13, 21)
console.log(multipliedMatrix.toString()); // output: matrix(1, 0, 0, 1, 26, 42)

规范

规范
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-multiply

浏览器兼容性

另见