SVGGraphicsElement: getScreenCTM() method

Baseline Widely available

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

Phương thức getScreenCTM() của giao diện SVGGraphicsElement đại diện cho ma trận chuyển đổi hệ tọa độ của phần tử hiện tại sang hệ tọa độ của viewport SVG cho đoạn tài liệu SVG.

Cú pháp

js
getScreenCTM()

Tham số

Không có.

Giá trị trả về

Một đối tượng DOMMatrix.

Ví dụ

Lấy ma trận biến đổi màn hình

html
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400">
  <!-- Hình tròn với dịch chuyển và tỷ lệ -->
  <circle
    id="circle"
    cx="50"
    cy="50"
    r="30"
    fill="blue"
    transform="translate(100, 150) scale(2)" />
</svg>
js
const circle = document.getElementById("circle");

// Lấy ma trận biến đổi màn hình hiện tại
const screenCTM = circle.getScreenCTM();

console.log("Screen transformation matrix:");
console.log(
  `a: ${screenCTM.a}, b: ${screenCTM.b}, c: ${screenCTM.c}, d: ${screenCTM.d}, e: ${screenCTM.e}, f: ${screenCTM.f}`,
);
// Output: a: 2, b: 0, c: 0, d: 2, e: 100, f: 150

Thông số kỹ thuật

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGGraphicsElement__getScreenCTM

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