SVGSVGElement: createSVGTransformFromMatrix() 方法
SVGSVGElement
接口的 createSVGTransformFromMatrix()
方法创建一个独立于任何文档树的 SVGTransform
对象,该对象基于给定的 DOMMatrix
对象。
语法
js
createSVGTransformFromMatrix(matrix)
参数
返回值
一个 SVGTransform
对象,它被初始化为给定的矩阵变换。如果 matrix
是 2D 的,则为 matrix()
变换;否则为 matrix3d()
变换。
示例
从矩阵创建变换
html
<svg id="exampleSVG" width="200" height="200">
<rect id="exampleRect" x="50" y="50" width="100" height="50" fill="blue" />
</svg>
js
const svgElement = document.getElementById("exampleSVG");
const rectElement = document.getElementById("exampleRect");
// Create a new matrix
const matrix = svgElement.createSVGMatrix();
matrix.a = 1; // Scale x
matrix.d = 1; // Scale y
matrix.e = 50; // Translate x
matrix.f = 50; // Translate y
// Create a new SVGTransform from the matrix
const transform = svgElement.createSVGTransformFromMatrix(matrix);
// Apply the transform to the rectangle
rectElement.transform.baseVal.appendItem(transform);
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGSVGElement__createSVGTransformFromMatrix |
浏览器兼容性
加载中…