SVGEllipseElement: cx 属性
SVGEllipseElement
接口的只读属性 cx
描述了椭圆中心的 x 轴坐标,其类型为
。它反映了 SVGAnimatedLength
元素上 <ellipse>
属性的计算值。cx
该属性的值可以是
、<length>
或 <percentage>
。<number>
的数值是椭圆中心在用户坐标系统中的 x 坐标。SVGAnimatedLength.baseVal
值
一个 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 |
浏览器兼容性
加载中…