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ố sxsy xác định lượng co giãn.

Cú pháp

js
setScale(sx, sy)

Tham số

sx

Một số thực xác định lượng co giãn theo trục X.

sy

Một số thực xác định lượng co giãn theo trục Y.

Giá trị trả về

Không có (undefined).

Ngoại lệ

NoModificationAllowedError DOMException

Được ném ra nếu thuộc tính hoặc đối tượng SVGTransform là 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

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGTransform__setScale

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