SVGUseElement: y 屬性
SVGUseElement 介面的只讀屬性 y 使用 SVGAnimatedLength 物件描述了引用元素的起始點的 y 軸座標。它反映了 <use> 元素上 y 屬性的計算值。
該屬性值可以是 <length>、<percentage> 或 <number>。SVGAnimatedLength.baseVal 的數值是以使用者座標系表示的引用元素的左上角的 y 座標。
值
一個 SVGAnimatedLength 物件。
示例
給定以下 SVG
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<circle id="circle1" cx="50" cy="50" r="40" fill="blue" />
<circle id="circle2" cx="50" cy="50" r="40" fill="red" />
</defs>
<use x="50%" y="50%" href="#circle1" />
<use x="25%" y="25%" href="#circle2" />
</svg>
我們可以訪問 y 屬性的計算值
js
const uses = document.querySelectorAll("use");
const yUse1 = uses[0].y;
const yUse2 = uses[1].y;
console.log(yUse1.baseVal.value); // output: 100 (50% of 200)
console.log(yUse2.baseVal.value); // output: 50 (25% of 200)
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGUseElement__y |
瀏覽器相容性
載入中…