SVGLineElement: y1 属性
SVGLineElement
接口的只读属性 y1
使用 SVGAnimatedLength
描述 SVG 线条在 y 轴上的起点。它反映了 <line>
元素的 y1
几何属性。
属性值可以是 <length>
、<percentage>
或 <number>
。SVGAnimatedLength.baseVal
的数值表示用户坐标系中 y 轴上的起点长度。
值
一个 SVGAnimatedLength
对象。
示例
给定以下 SVG
html
<svg viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
<line x1="20" y1="30" x2="40" y2="50" stroke="blue" stroke-width="2" />
<line x1="15%" y1="5%" x2="30%" y2="60%" stroke="red" stroke-width="4" />
</svg>
我们可以访问 y1
属性的计算值
js
const lines = document.querySelectorAll("line");
const y1Pos0 = lines[0].y1;
const y1Pos1 = lines[1].y1;
console.dir(y1Pos0.baseVal.value); // output: 30 (the value of `y1`)
console.dir(y1Pos1.baseVal.value); // output: 10 (5% of 200)
规范
规范 |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGLineElement__y1 |
浏览器兼容性
加载中…