SVGTransform: setTranslate() 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 setTranslate() của giao diện SVGTransform đặt kiểu biến đổi thành SVG_TRANSFORM_TRANSLATE, với các tham số tx và ty xác định lượng dịch chuyển.
Cú pháp
js
setTranslate(tx, ty)
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ụ
>Đặt giá trị dịch chuyển
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ị dịch chuyển cho biến đổi
transform.setTranslate(100, 50);
// Xuất ra chi tiết dịch chuyển
console.log(`X Translation: ${transform.matrix.e}`); // Đầu ra: 100
console.log(`Y Translation: ${transform.matrix.f}`); // Đầu ra: 50
Thông số kỹ thuật
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2> # __svg__SVGTransform__setTranslate> |