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ố txty xác định lượng dịch chuyển.

Cú pháp

js
setTranslate(tx, ty)

Tham số

tx

Một số thực xác định lượng dịch chuyển theo trục X.

ty

Một số thực xác định lượng dịch chuyể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ụ

Đặ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

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