I am attempting to position an arrow at the midpoint of a bezier curve. The method outlined in this StackOverflow question, which involves using <animateMotion>
to move a <path>
representing the arrow and freezing it at the center of the curve, only works in Firefox. Due to the frequent changes in my curve's points, I prefer not to use marker-mid
as recalculating the midpoint each time is costly for me.
<svg viewBox="0 0 500 500">
<g>
<path id="path1" d="M291.698 268.340 C321.698 268.340, 411.904 93.133 441.904 93.133"></path>
<path class="path_arrow" d="M0,0 L6,6 L0,12" transform="translate(-3,-6)">
<animateMotion dur="0s" rotate="auto" fill="freeze" keyTimes="0;1" keyPoints="0.5;0.5">
<mpath xlink:href="#path1"></mpath>
</animateMotion>
</path>
</g>
<g transform="translate(166.698,243.340)">
<circle r="5" class="p1"></circle>
</g>
<g transform="translate(441.904,68.133)" >
<circle r="5" class="p2"></circle>
</g>
</svg>
Is there a way to achieve this using CSS Animations instead of relying on <animateMotion>
?
EDIT 1:
The endpoints of the curve are draggable, causing the curve's points to frequently change. The goal is to animate the arrow to the center of the curve without manually calculating the midpoints. https://i.sstatic.net/RvBLV.png
EDIT 2:
Following Kaiido's suggestion, I added calcMode="linear"
resulting in the arrow being correctly positioned along the path. However, when repositioning the endpoint by dragging, the arrow remains in its original position in Chrome instead of moving along with the parent path. This behavior is consistent with Firefox but not Chrome.