SVGEllipseElement: cx 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

SVGEllipseElement 接口的只读属性 cx 描述了椭圆中心的 x 轴坐标,其类型为 SVGAnimatedLength。它反映了 <ellipse> 元素上 cx 属性的计算值。

该属性的值可以是 <length><percentage><number>SVGAnimatedLength.baseVal 的数值是椭圆中心在用户坐标系统中的 x 坐标。

一个 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>

我们可以访问 cx 属性的计算值

js
const ellipses = document.querySelectorAll("ellipse");
const cxPos0 = ellipses[0].cx;
const cxPos1 = ellipses[1].cx;

console.dir(cxPos0.baseVal.value); // output: 50
console.dir(cxPos1.baseVal.value); // output: 50 (25% of 200)

规范

规范
Scalable Vector Graphics (SVG) 2
# __svg__SVGEllipseElement__cx

浏览器兼容性

另见