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

浏览器兼容性

另见