DOMMatrixReadOnly: inverse() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Note: This feature is available in Web Workers.

Phương thức inverse() của giao diện DOMMatrixReadOnly tạo một ma trận mới là nghịch đảo của ma trận gốc. Nếu ma trận không thể nghịch đảo, tất cả các thành phần của ma trận mới sẽ được đặt thành NaN và thuộc tính is2D của nó được đặt thành false. Ma trận gốc không bị thay đổi.

Để thay đổi ma trận khi nghịch đảo, hãy xem DOMMatrix.invertSelf().

Cú pháp

js
inverse()

Tham số

Không có.

Giá trị trả về

Một DOMMatrix.

Ví dụ

js
const matrix = new DOMMatrixReadOnly().rotate(30);
const invertedMatrix = matrix.inverse();
console.log(matrix.toString());
// output: matrix(0.866, 0.5, -0.5, 0.866, 0, 0)
console.log(invertedMatrix.toString());
// output: matrix(0.866, -0.5, 0.5, 0.866, 0, 0)

Thông số kỹ thuật

Specification
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-inverse

Tương thích trình duyệt

Xem thêm