SVGAnimatedRect: animVal 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

SVGAnimatedRect 接口的只读属性 animVal,表示 SVG 元素的 viewBox 属性的当前动画值,其类型为一个只读的 DOMRectReadOnly 对象。在动画期间,它提供了对矩形动态状态的访问,包括 xywidthheight 值。

如果没有应用动画,animVal 属性将反映 SVG 元素的 viewBox 属性值,并且将与 SVGAnimatedRect.baseVal 相同。

一个 DOMRectReadOnly 对象,表示 viewBox 属性的动画值。

示例

html
<svg viewBox="0 0 200 100" id="mySvg">
  <rect width="100" height="100" fill="blue" />
</svg>
js
const svgElement = document.getElementById("mySvg");
const animatedRect = svgElement.viewBox.animVal;

// Log the animated value (assuming an animation is applied)
console.log(animatedRect.x);
console.log(animatedRect.y);
console.log(animatedRect.width);
console.log(animatedRect.height);

规范

规范
Scalable Vector Graphics (SVG) 2
# __svg__SVGAnimatedRect__animVal

浏览器兼容性

另见