【发布时间】:2022-01-06 18:12:56
【问题描述】:
下面是定义的polygon,然后是used,同时应用了相同的linearGradient和line:
-
polygon是used,因为会有很多类似的行。 - 箭头使用渐变填充的原因是因为它会在绘制线条时沿着
line的路径进行动画处理,因此希望它的填充随着gradientUnits="userSpaceOnUse"的移动而改变。 (我打算使用this excellent technique的派生。)
(line 实际上是一个更复杂的多角度polyline,但这段代码简化了事情。)
This codepen 展示了带有一些变体和注释的视觉结果。
.line {
fill: none;
stroke-width: 60px;
stroke: url(#grad);
}
.head-grad {
fill: url(#grad);
}
<svg viewBox="0 0 1600 200">
<defs>
<polygon id="head" points="0 0, 42 0, 92 50, 42 100, 0 100, 50 50, 0 0"/>
<linearGradient id="grad" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#901500"/>
<stop offset="0.9" stop-color="#eb7500"/>
</linearGradient>
</defs>
<line class="line" x1="1540" y1="100" y2="100"/>
<use href="#head" class="head-grad" x="1490" y="50"/>
</svg>
谁能解释我哪里出错了,或者是否有另一种方法更适合让箭头的填充匹配它在线上的相对位置?
【问题讨论】:
标签: animation svg linear-gradients