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 |
浏览器兼容性
加载中…