SVGTransform:setTranslate() 方法
SVGTransform 介面的 setTranslate() 方法將變換型別設定為 SVG_TRANSFORM_TRANSLATE,其中引數 tx 和 ty 定義了平移量。
語法
js
setTranslate(tx, ty)
引數
返回值
無(undefined)。
異常
NoModificationAllowedErrorDOMException-
如果屬性或
SVGTransform物件是隻讀的,則丟擲此異常。
示例
設定平移值
js
// Select an SVG element and create a transform object
const svgElement = document.querySelector("svg");
const transform = svgElement.createSVGTransform();
// Set the translation values for the transform
transform.setTranslate(100, 50);
// Output the translation details
console.log(`X Translation: ${transform.matrix.e}`); // Output: 100
console.log(`Y Translation: ${transform.matrix.f}`); // Output: 50
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGTransform__setTranslate |
瀏覽器相容性
載入中…