SVGTransform:setScale() 方法
SVGTransform
接口的 setScale()
方法将变换类型设置为 SVG_TRANSFORM_SCALE
,参数 sx
和 sy
定义缩放量。
语法
js
setScale(sx, sy)
参数
返回值
无(undefined
)。
异常
NoModificationAllowedError
DOMException
-
如果属性或
SVGTransform
对象是只读的,则抛出此异常。
示例
缩放 SVG 元素
js
// Select an SVG element and create a transform object
const svgElement = document.querySelector("svg");
const transform = svgElement.createSVGTransform();
// Set the scale values for the transform
transform.setScale(2, 3);
// Output the scale details
console.log(`Scale X: ${transform.matrix.a}`); // Output: 2
console.log(`Scale Y: ${transform.matrix.d}`); // Output: 3
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGTransform__setScale |
浏览器兼容性
加载中…