SVGLinearGradientElement: y1 屬性
SVGLinearGradientElement 介面的只讀屬性 y1 描述了漸變的起始點的 y 軸座標,其型別為 SVGAnimatedLength。它反映了 <linearGradient> 元素上 y1 屬性的計算值。
該屬性值是一個 <length>、<percentage> 或 <number>。SVGAnimatedLength.baseVal 的數值是漸變起點在使用者座標系中的 y 座標。
值
一個 SVGAnimatedLength 物件。
示例
給定以下 SVG
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="gradient1" x1="50%" y1="0%" x2="50%" y2="100%">
<stop offset="0%" stop-color="blue" />
<stop offset="100%" stop-color="white" />
</linearGradient>
<linearGradient id="gradient2" x1="25%" y1="0%" x2="75%" y2="100%">
<stop offset="0%" stop-color="red" />
<stop offset="100%" stop-color="yellow" />
</linearGradient>
</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>
我們可以訪問 y1 屬性的計算值
js
const linearGradients = document.querySelectorAll("linearGradient");
const y1Gradient1 = linearGradients[0].y1;
const y1Gradient2 = linearGradients[1].y1;
console.dir(y1Gradient1.baseVal.value); // output: 0 (0% of 200)
console.dir(y1Gradient2.baseVal.value); // output: 0 (0% of 200)
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGLinearGradientElement__y1 |
瀏覽器相容性
載入中…