我有这样一条曲线svg线
<path d="M70,260 C105,260 126,330 160,330"
style="stroke: #ff4444;stroke-width:2; fill:none;"/>我想要的是在我的行中间添加另一个svg (如149657),指向终点。
有什么想法吗?
发布于 2018-02-09 12:33:48
有许多方法可以做到这一点。
一种方法是“欺骗”一点,并使用<textPath>和箭头字符。
SVG marker-mid on specific point on path
这有点麻烦,并不是所有浏览器都能可靠地工作,但它可能足以满足您的需要。
另一种方法是将路径分成两部分(使用De Casteljau's algorithm),并使用<marker>。
<svg viewBox="0 200 200 200" width="400">
<defs>
<marker id="Triangle"
viewBox="0 0 10 10" refX="0" refY="5"
markerUnits="strokeWidth"
markerWidth="4" markerHeight="3"
orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" />
</marker>
</defs>
<path d="M 70,260
C 87.5,260 101.5,277.5 115.375,295
C 129.25,312.5 143,330 160,330"
style="stroke: #ff4444; stroke-width:2; fill:none; marker-mid:url(#Triangle)"/>
</svg>
还有其他使用Javascript的方法。例如,您可以使用SVGPathElement.getPointAtLength()方法来查找路径中心的坐标。然后在那个位置定位一个三角形。
https://stackoverflow.com/questions/48701971
复制相似问题