SVGAnimatedRect: baseVal 屬性

Baseline 已廣泛支援

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

SVGAnimatedRect 介面的只讀屬性 baseVal 表示 SVG 元素的 viewBox 屬性的當前非動畫值。

此屬性反映了 SVG 元素的 viewBox 屬性值,形式為一個只讀的 DOMRect 物件。它提供了對 viewBox 屬性定義的靜態矩形的訪問,包括 xywidthheight 值。

一個表示 viewBox 屬性當前非動畫值的 DOMRect 物件。

示例

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.baseVal;

// Access the non-animated base value
console.log(animatedRect.x); // 0
console.log(animatedRect.y); // 0
console.log(animatedRect.width); // 200
console.log(animatedRect.height); // 100

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGAnimatedRect__baseVal

瀏覽器相容性

另見