简体   繁体   English

如何在SVG中绘制箭头?

[英]How to draw an arrow in SVG?

I need to make it flexible.我需要让它灵活。 It can be some type of lines and arrows on the end of lines.它可以是某种类型的线条和线条末端的箭头。

So, I decided to create two SVG objects: lines and an arrowhead.因此,我决定创建两个 SVG 对象:线条和箭头。

How to draw an arrowhead on the end or beginning of the line?如何在行的末尾或开头绘制箭头?

My line is:我的线路是:

 <svg width="500" height="100"> <line x1="0" y1="80" x2="100" y2="20" stroke="black" /> </svg>

Upu can use defs and path http://jsfiddle.net/jxtfeqag/ upu 可以使用 defs 和路径http://jsfiddle.net/jxtfeqag/

<svg >
    <defs>
      <marker id='head' orient="auto"
        markerWidth='3' markerHeight='4'
        refX='0.1' refY='2'>
        <path d='M0,0 V4 L2,2 Z' fill="black"/>
      </marker>
    </defs>

    <path
      id='arrow-line'
      marker-end='url(#head)'
      stroke-width='4'
      fill='none' stroke='black'  
      d='M0,0, 80 100,120'
      />

    </svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM