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

瀏覽器相容性

另見