y2

y2 属性用于指定需要一个以上坐标的 SVG 元素的第二个 y 坐标。只需要一个坐标的元素则使用 y 属性。

元素

你可以在下面部分描述的 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">
  <!--
  By default the gradient vector end at the top right
  corner of the bounding box of the shape it is applied to.
  -->
  <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)" />

  <!--
  Here the gradient vector end at the bottom right
  corner of the bounding box of the shape it is applied to.
  -->
  <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
# LinearGradientElementY2Attribute

浏览器兼容性

svg.elements.line.y2

svg.elements.linearGradient.y2