SVG marker-mid on specific point on path

后端 未结 2 1063
忘掉有多难
忘掉有多难 2020-12-17 00:43

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



        
相关标签:
2条回答
  • 2020-12-17 01:14

    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.

    You are drawing a line with vertices A, B, and C, so by definition the marker will be drawn at B.

    If you want a marker to be drawn between A and B you will need to draw a path from A to the midpoint AB to B.

    <svg width="200" height="150">
      <defs>
        <marker id="markerArrow" markerWidth="13" markerHeight="13" refX="2" refY="6" orient="auto">
          <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000;" />
        </marker>
      </defs>
      <path d='M0,0 L50,50 L100, 100' style='marker-mid:url(#markerArrow); stroke: #000'/>
      <path d='M100,100 L125, 100 L150, 100' style='marker-mid:url(#markerArrow); stroke: #000' />
    </svg>

    0 讨论(0)
  • 2020-12-17 01:26

    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>

    0 讨论(0)
提交回复
热议问题