SVGSVGElement: x 屬性

Baseline 已廣泛支援

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

SVGSVGElement 介面的只讀屬性 x 描述了該 SVG 位置的水平座標,它是一個 SVGAnimatedLength 物件。當一個 <svg> 元素巢狀在另一個 <svg> 元素內部時,該水平座標是使用者座標系中的一個長度,表示從使用者座標系原點沿 x 軸偏移的距離。其語法與 <length> 相同。

它反映了 <svg> 元素的 x 幾何屬性。預設值為 0x 屬性對最外層的 <svg> 元素沒有影響;僅對巢狀的元素有影響。CSS x 屬性優先於 <svg> 元素的 x 屬性,因此該值可能不反映元素的實際外觀。

一個 SVGAnimatedLength 物件。

示例

js
const svg = document.querySelector("svg");
const leftPosition = svg.x;
console.dir(leftPosition.baseVal.value); // the `x` value

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGSVGElement__x

瀏覽器相容性

另見