SVGLineElement: y2 屬性
SVGLineElement 介面的只讀屬性 y2 以 SVGAnimatedLength 的形式描述了線條結束點的 v 軸座標值。它反映了 <line> 元素的 y2 幾何屬性。
屬性值可以是 <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>
我們可以訪問 y2 屬性的計算值
js
const lines = document.querySelectorAll("line");
const y2Pos0 = lines[0].y2;
const y2Pos1 = lines[1].y2;
console.dir(y2Pos0.baseVal.value); // output: 50 (the value of `y2`)
console.dir(y2Pos1.baseVal.value); // output: 120 (60% of 200)
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGLineElement__y2 |
瀏覽器相容性
載入中…