SVGEllipseElement: cy 屬性

Baseline 已廣泛支援

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

SVGEllipseElement 介面的只讀屬性 cy 使用 SVGAnimatedLength 物件描述了橢圓中心的 y 軸座標。它反映了 <ellipse> 元素上 cy 屬性的計算值。

該屬性值可以是 <length><percentage><number>SVGAnimatedLength.baseVal 的數值是橢圓中心在使用者座標系中的 y 座標。

一個 SVGAnimatedLength 物件。

示例

給定以下 SVG

html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <ellipse cx="50" cy="75" rx="30" ry="20" fill="blue" />
  <ellipse cx="25%" cy="50%" rx="10%" ry="5%" fill="red" />
</svg>

我們可以訪問 cy 屬性的計算值

js
const ellipses = document.querySelectorAll("ellipse");
const cyPos0 = ellipses[0].cy;
const cyPos1 = ellipses[1].cy;

console.dir(cyPos0.baseVal.value); // output: 75
console.dir(cyPos1.baseVal.value); // output: 100 (50% of the viewBox height, 200)

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGEllipseElement__cy

瀏覽器相容性

另見