SVGTransform:setMatrix() 方法
SVGTransform
接口的 setMatrix()
方法将变换类型设置为 SVG_TRANSFORM_MATRIX
,并使用 matrix
参数定义新的变换。
请注意,matrix
参数中的值会被复制,这意味着调用此方法后对 matrix
对象所做的更改不会影响变换。
语法
js
setMatrix(matrix)
参数
返回值
无(undefined
)。
异常
NoModificationAllowedError
DOMException
-
如果属性或
SVGTransform
对象是只读的,则抛出此异常。
示例
设置变换矩阵
js
// Get an SVG element and create a transform object
const svgElement = document.querySelector("svg");
const transform = svgElement.createSVGTransform();
// Create a DOMMatrix with specific values
const matrix = new DOMMatrix();
matrix.a = 1; // Scale X
matrix.d = 1; // Scale Y
matrix.e = 50; // Translate X
matrix.f = 50; // Translate Y
// Set the transform to the new matrix
transform.setMatrix(matrix);
console.dir(transform.matrix); // Output: SVGMatrix { a: 1, b: 0, c: 0, d: 1, e: 50, f: 50 }
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGTransform__setMatrix |
浏览器兼容性
加载中…