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

浏览器兼容性