Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

javascript - SVG marker-mid on specific point on path

I got some code that generates pathes on canvas. the path objects looks similar to this :

<path class="link" d="M450,215.L265,236L225,236" style="stroke-width: 1;"></path>

and on view (a,b,c letters are just for explaining the problem):

enter image description here

My problem is that I want to draw some arrow (marker) on the middle of the line, between "a" to "b", but when I create a marker and do a marker-mid attribute, its generates on b point.

I've tried to do some point between a and b, but then marker-mid did the arrows both there and both on b point.

from WEB API documentation :

The marker-mid defines the arrowhead or polymarker that shall be drawn at every vertex other than the first and last vertex of the given element or basic shape.

How can I disable the marker on point b? Or how can I make something like arrow between a-b ? Thanks !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

sometimes its not so easy to split the path at any point you like. Then you can use text on a path with startOffset to position an "arrow" at any point on a path...

path {
  fill: none;
  stroke: red;
  stroke-width: 3
}
text {
  font-size: 35px;
  fill: red;
  dominant-baseline: central
}
<svg viewBox="0 0 500 500" width="300px" height="300px">
  <path class="link" id="path1" d="M0 0 L200 400A300 300 0 0 1 490 150"></path>
  <text >
    <textPath xlink:href="#path1" startOffset="10%">?</textPath>
    <textPath xlink:href="#path1" startOffset="20%">?</textPath>
    <textPath xlink:href="#path1" startOffset="30%">?</textPath>
    <textPath xlink:href="#path1" startOffset="40%">?</textPath>
    <textPath xlink:href="#path1" startOffset="50%">?</textPath>
    <textPath xlink:href="#path1" startOffset="60%">?</textPath>
    <textPath xlink:href="#path1" startOffset="70%">?</textPath>
    <textPath xlink:href="#path1" startOffset="80%">?</textPath>
    <textPath xlink:href="#path1" startOffset="90%">?</textPath>
  </text>
</svg>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...