元素
你可以将此属性与以下各节所述的 SVG 元素一起使用。
<line>
对于 <line>,y2 定义线段终点的 y 坐标。
| 值 | <length>|<percentage>|<number> |
|---|---|
| 默认值 | 0 |
| 动画性 | 是 |
html
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
<line x1="1" x2="9" y1="5" y2="1" stroke="red" />
<line x1="1" x2="9" y1="5" y2="5" stroke="green" />
<line x1="1" x2="9" y1="5" y2="9" stroke="blue" />
</svg>
<linearGradient>
对于 <linearGradient>,y2 定义用于映射色标值的渐变向量终点的 y 坐标。该属性的具体行为受 gradientUnits 属性影响。
| 值 | <length> |
|---|---|
| 默认值 | 0% |
| 动画性 | 是 |
html
<svg viewBox="0 0 20 10" xmlns="http://www.w3.org/2000/svg">
<!--
默认情况下,渐变向量终止于其所应用到的形状的包围盒右上角。
-->
<linearGradient y2="0%" id="g0">
<stop offset="5%" stop-color="black" />
<stop offset="50%" stop-color="red" />
<stop offset="95%" stop-color="black" />
</linearGradient>
<rect x="1" y="1" width="8" height="8" fill="url(#g0)" />
<!--
此处渐变向量终止于其所应用到的形状的包围盒右下角。
-->
<linearGradient y2="100%" id="g1">
<stop offset="5%" stop-color="black" />
<stop offset="50%" stop-color="red" />
<stop offset="95%" stop-color="black" />
</linearGradient>
<rect x="11" y="1" width="8" height="8" fill="url(#g1)" />
</svg>
示例
html
<svg viewBox="0 0 25 25" xmlns="http://www.w3.org/2000/svg">
<line x1="2" x2="22" y1="20" y2="0" stroke="red" />
<line x1="2" x2="22" y1="20" y2="10" stroke="green" />
<line x1="2" x2="22" y1="20" y2="20" stroke="blue" />
</svg>
规范
| 规范 |
|---|
| Scalable Vector Graphics (SVG) 2> # LineElementY2Attribute> |
| Scalable Vector Graphics (SVG) 2> # LinearGradientElementY2Attribute> |