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

瀏覽器相容性

另見