DOMMatrixReadOnly: is2D 属性

Baseline 已广泛支持

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

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

DOMMatrixReadOnly 接口的只读属性 is2D 是一个布尔标志,当矩阵为 2D 时为 true。如果矩阵被初始化为 2D 矩阵并且只应用了 2D 转换操作,则该值为 true。否则,矩阵在 3D 中定义,is2Dfalse

一个布尔值。

示例

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

// Transform in a 2D space
console.log(matrix.rotate(30).is2D); // output: true

// Apply a 3D transform
console.log(matrix.rotate(10, 20, 1).is2D); // output: false

规范

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

浏览器兼容性

另见