DOMMatrixReadOnly:isIdentity 属性

Baseline 已广泛支持

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

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

DOMMatrixReadOnly 接口的只读 isIdentity 属性是一个布尔值,如果矩阵是单位矩阵,则该属性值为 true

单位矩阵是一种矩阵,其中所有值都为 0除了从左上角到右下角的主对角线上的值(换句话说,每个方向上的偏移量都相等)。

一个布尔值。

示例

js
// Initialize a 2D matrix
const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.isIdentity); // output: true

// Apply a transform that has no effect
console.log(matrix.translate(0).isIdentity); // output: true

// Apply a transform with effect: this rotates the matrix by 30deg
console.log(matrix.rotate(30).isIdentity); // output: false

规范

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

浏览器兼容性

另见