【发布时间】:2014-12-26 14:09:30
【问题描述】:
我是 SVG 世界的新手,当我想“绘制”弯曲的箭头时遇到了一些问题。
基本上,我想创建一个类似于this article 中解释的动画,但在路径的末尾有一个形状以显示箭头。
以下是我用于直箭头的代码:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<defs>
<marker
id="arrow"
orient="auto"
viewBox="0 0 10 10"
markerWidth="3"
markerHeight="4"
markerUnits="strokeWidth"
refX="1" refY="5">
<polyline points="0,0 10,5 0,10 1,5" fill="black" />
</marker>
</defs>
<path
id="line"
marker-end="url(#arrow)"
stroke-width="3"
fill="none"
stroke="black">
<animate
dur="2s"
repeatCount="indefinite"
attributeName="d"
values="M10,10 L10,10; M10,10 L45,25;" />
</path>
加上一点 CSS:
#line
{
stroke-dasharray: 5;
stroke-dashoffset: 10;
-webkit-animation: draw 1s linear infinite;
}
@-webkit-keyframes draw
{
to { stroke-dashoffset: 0;}
}
结果如下:
这很酷,但现在我想要一个弯曲的箭头。所以我更新了动画标签,如下所示:
<animate
dur="2s"
repeatCount="indefinite"
attributeName="d"
values="M7,121 C7,121 7,121 7,121; M7,121 C66,4 143,75 147,125" />
我刚刚更改了动画路径,以便获得弯曲的路径。但结果如下:
我认为这很合乎逻辑,但这不是我想要的。标记当前正在直线移动;它应该遵循绘图路径。
说实话,我不知道该怎么做,任何建议都会很棒:)
你可以找到a JSFiddle here。
如您所见,这些实验中没有使用 JS,如果我们可以避免使用这种语言而只使用 SVG+CSS,那就太好了。
提前致谢!
【问题讨论】: