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 |
瀏覽器相容性
載入中…