SVGRadialGradientElement: cy 属性
SVGRadialGradientElement
接口的只读属性 cy
以 SVGAnimatedLength
的形式描述了径向渐变中心的 y 轴坐标。它反映了 <radialGradient>
元素上 cy
属性的计算值。
该属性值可以是 <length>
、<percentage>
或 <number>
。SVGAnimatedLength.baseVal
的数值是径向渐变中心在用户坐标系中的 y 坐标。
值
一个 SVGAnimatedLength
对象。
示例
给定以下 SVG
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="gradient1" cx="50" cy="75" r="30">
<stop offset="0%" stop-color="blue" />
<stop offset="100%" stop-color="white" />
</radialGradient>
<radialGradient id="gradient2" cx="25%" cy="50%" r="10%">
<stop offset="0%" stop-color="red" />
<stop offset="100%" stop-color="yellow" />
</radialGradient>
</defs>
<rect x="0" y="0" width="200" height="100" fill="url(#gradient1)" />
<rect x="0" y="100" width="200" height="100" fill="url(#gradient2)" />
</svg>
我们可以访问 cx
属性的计算值
js
const radialGradients = document.querySelectorAll("radialGradient");
const cyGradient1 = radialGradients[0].cy;
const cyGradient2 = radialGradients[1].cy;
console.dir(cyGradient1.baseVal.value); // output: 75
console.dir(cyGradient2.baseVal.value); // output: 100 (50% of 200)
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGRadialGradientElement__cy |
浏览器兼容性
加载中…