DOMMatrix: preMultiplySelf() 方法

Baseline 已廣泛支援

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

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

preMultiplySelf() 方法是 DOMMatrix 介面的一個方法,它透過將當前矩陣與指定的 DOMMatrix 進行前乘來修改當前矩陣。這等價於點積 B⋅A,其中矩陣 A 是源矩陣,B 是作為輸入傳遞給該方法的矩陣。如果沒有指定乘數矩陣,則當前矩陣將與一個除了右下角及其左上角元素(即 m33m34)之外所有元素都為 0 的矩陣相乘。這些元素預設值為 1

語法

js
preMultiplySelf()
preMultiplySelf(otherMatrix)

引數

otherMatrix 可選

DOMMatrix 乘數。

返回值

返回自身;一個已更新為應用乘法結果的 DOMMatrix

示例

js
const matrix = new DOMMatrix().translate(3, 22);
const otherMatrix = new DOMMatrix().translateSelf(15, 45);

console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 3, 22)
console.log(otherMatrix.toString()); // output: matrix(1, 0, 0, 1, 15, 45)

matrix.preMultiplySelf(otherMatrix);

console.log(matrix.toString()); // output: matrix(1, 0, 0, 1, 18, 67)
console.log(otherMatrix.toString()); // output: matrix(1, 0, 0, 1, 15, 45)

規範

規範
Geometry Interfaces Module Level 1
# dom-dommatrix-premultiplyself

瀏覽器相容性

另見