假设我有一个跟随标记(我想在dom中只有一个标记元素):
<marker id="arrow" viewBox="0 -5 10 10" refX="22.5" refY="0" markerWidth="20" markerHeight="20" orient="auto"><path d="M0,-5L10,0L0,5" fill="#000000"></path></marker>
我用它在线上画箭头:
<line stroke="black" stroke-width="0.5" x1="1190.5337908659556" y1="814.1321248143822" x2="1183.09985813189" y2="-58.79906521075237" marker-end="url(#arrow)" display="inline"></line>
<line stroke="black" stroke-width="0.5" x1="797.4477436706952" y1="325.5996932062993" x2="877.7838866381225" y2="631.7793113188723" marker-end="url(#arrow)" display="inline"></line>
有没有办法通过在引用标记的线元素上使用某个属性来沿着线移动箭头?
答案 0 :(得分:3)
您需要为应用标记的行的终点设置动画。
在下面的示例中,我添加了第二行。然后,我们将x2
和y2
属性从该行的开头设置为结尾。所以它从零长度开始,最终与原始线相同。
<svg viewBox="600 300 600 400">
<defs>
<marker id="arrow" viewBox="0 -5 10 10" refX="10" refY="0" markerWidth="20" markerHeight="20" orient="auto"><path d="M0,-5L10,0L0,5" fill="#000000"></path></marker>
</defs>
<!-- original path -->
<line stroke="black" stroke-width="0.5" x1="797.4477436706952" y1="325.5996932062993" x2="877.7838866381225" y2="631.7793113188723"/>
<!-- original path -->
<line stroke="none" stroke-width="0.5" x1="797.44" y1="325.59" x2="797.44" y2="325.59" marker-end="url(#arrow)">
<animate attributeName="x2" from="797.44" to="877.78" dur="2s" fill="freeze"/>
<animate attributeName="y2" from="325.59" to="631.77" dur="2s" fill="freeze"/>
</line>
</svg>
答案 1 :(得分:0)