SVGTransform: setScale() 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 setScale() của giao diện SVGTransform đặt kiểu biến đổi thành SVG_TRANSFORM_SCALE, với các tham số sx và sy xác định lượng co giãn.
Cú pháp
js
setScale(sx, sy)
Tham số
Giá trị trả về
Không có (undefined).
Ngoại lệ
NoModificationAllowedErrorDOMException-
Được ném ra nếu thuộc tính hoặc đối tượng
SVGTransformlà chỉ đọc.
Ví dụ
>Co giãn một phần tử SVG
js
// Chọn phần tử SVG và tạo đối tượng transform
const svgElement = document.querySelector("svg");
const transform = svgElement.createSVGTransform();
// Đặt giá trị co giãn cho biến đổi
transform.setScale(2, 3);
// Xuất ra chi tiết co giãn
console.log(`Scale X: ${transform.matrix.a}`); // Đầu ra: 2
console.log(`Scale Y: ${transform.matrix.d}`); // Đầu ra: 3
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Scalable Vector Graphics (SVG) 2> # __svg__SVGTransform__setScale> |