SVGTransform: type 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGTransform 介面的只讀屬性 type 表示應用的變換的type,由此介面上定義的 SVG_TRANSFORM_* 常量之一指定。

一個 integer;值的型別為無符號短整型。

示例

確定變換的型別

html
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <rect id="rect" x="50" y="50" width="100" height="100" fill="blue" />
</svg>
js
const rect = document.getElementById("rect");
const transformList = rect.transform.baseVal;

// Create and add a translation transform
const translateTransform = rect.ownerSVGElement.createSVGTransform();
translateTransform.setTranslate(20, 30);
transformList.appendItem(translateTransform);

// Check the type of the added transform
console.log(transformList.getItem(0).type); // Output: 2 (SVG_TRANSFORM_TRANSLATE)

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGTransform__type

瀏覽器相容性