SVG Scalable Vector Graphics

SVG ¥H XML ®æ¦¡©w¸q¹Ï§Î¡C

±N SVG ª½±µ´O¤J HTML ­¶­±:

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40"
  	stroke="green" stroke-width="4" fill="yellow" />
</svg>

SVG §Îª¬

SVG ¦³¤@¨Ç¹w©w¸qªº§Îª¬¤¸¥ó¥i¨Ñ¨Ï¥Î¡G

SVG Rectangle - <rect>

¤¸¥ó¥Î©ó³Ð«Ø¯x§Î©M¯x§ÎªºÅÜÅé¡G
<svg width="400" height="110">
  <rect width="200" height="100" style="fill:rgb(0,0,255);
          stroke-width:3;stroke:rgb(0,0,0)" />
</svg>
¶ê¨¤¯x§Î´N¬O¦b¯x§Îªº rect ÄݩʤºÃB¥~¼W¥[rx¡Bryªº¶ê¨¤¥b®|ÄÝ©Ê
<svg width="400" height="110">
  <rect x="60" y="10" rx="10" ry="10" width="75" height="75"
          stroke="#FF5500" stroke-width="5" fill="#FFB255"/>
</svg>
fill-opacity Äݩʩw¸q¤F¶ñ¥RÃC¦âªº¤£³z©ú«×¡]0 ¨ì 1¡^
<svg width="400" height="180">
  <rect x="50" y="20" width="100" height="100"
  style="fill:blue;stroke:pink;stroke-width:5;
          fill-opacity:0.1;stroke-opacity:0.9" />
</svg>

SVG - <ellipse>

<svg height="140" width="400">
  <ellipse cx="200" cy="80" rx="100" ry="50"
  style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>

SVG - <line>

<svg height="120" width="500">
  <line x1="0" y1="0" x2="200" y2="100"
          style="stroke:rgb(255,0,0);stroke-width:2" />
</svg>

SVG - <polygon>

¦hÃä§Î¥Ñª½½uºc¦¨¡A§Îª¬¬O¡§«Ê³¬ªº¡¨¡]©Ò¦³ªº½u³£³s±µ°_¨Ó¡^¡C
<svg height="250" width="500">
  <polygon points="220,10 300,210 170,250 123,234"
          style="fill:lime;stroke:purple;stroke-width:1" />
</svg>
¨Ï¥Î <polygon> ¤¸¥ó³Ð«Ø¤@­Ó¬P§Î¡G
<svg height="210" width="500">
  <polygon points="100,10 40,198 190,78 10,78 160,198"
          style="fill:lime;stroke:purple;stroke-width:5;
          fill-rule:evenodd;" />
</svg>

SVG - <polyline>

<svg height="200" width="500">
  <polyline points="20,20 40,25 60,40 80,120 120,140 200,180"
  style="fill:none;stroke:black;stroke-width:3" />
</svg>

SVG - <image>

<svg width="100" height="100"
  xmlns="http://www.w3.org/2000/svg">
  <image href="../svg/mdn_logo_only_color.png" height="100" width="100"/>
</svg>

SVG - <pattern>

¤¸¥ó©w¸q¤F¤@­Ó¹Ï§Îª«¥ó¡A¸Óª«¥ó¥i¥H¥H­«½Æªº x ©M y §¤¼Ð¶¡¹j¡]¡§¥­¾Q¡¨¡^­«·sø»s¥HÂл\¤@­Ó°Ï°ì¡C

¥Ñ¨ä¥L¹Ï§Î¤¸¥ó¤Wªº fill ©M/©Î stroke ÄݩʤޥΡA¥H¨Ï¥Î¤Þ¥Îªº¼Ò¦¡¶ñ¥R©Î´yÃä³o¨Ç¤¸¥ó¡C

<svg viewBox="0 0 230 200" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <pattern id="star" viewBox="0,0,10,10" width="10%" height="10%">
      <polygon points="0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2"/>
    </pattern>
  </defs>
  <circle cx="50"  cy="60" r="50" fill="url(#star)"/>
  <circle cx="120" cy="60" r="40" fill="none"
        stroke-width="20" stroke="url(#star)"/>
</svg>
<pattern>¥i¥H»s§@³z©ú­I´ºªº®ÄªG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
        <pattern id="checkerPattern" patternUnits="userSpaceOnUse"
             x="0" y="0" width="20" height="20" viewBox="0 0 10 10">
            <rect x="0" y="0" width="10" height="10" fill="#fff">
            <rect x="0" y="0" width="5" height="5" fill="#eee">
            <rect x="5" y="5" width="5" height="5" fill="#eee">
        </pattern>
    </defs>
    <rect width="100%" height="100%" x="0" y="0" stroke="#000"
            fill="url(#checkerPattern)" style="pointer-events:none">
</svg>

SVG «þ¨© - <use>

¤¸¥ó±q SVG ¤åÀɤ¤Àò¨ú¸`ÂI¡A¨Ã¦b¨ä¥L¦a¤è½Æ»s¥¦­Ì¡C
    <svg width="400" height="200"
        xmlns="http://www.w3.org/2000/svg">
        <circle id="gfg" cx="100" cy="100" r="40"/>

        <use href="#gfg" x="110" fill="blue"></use>
    </svg>

SVG - <defs>

defs ¤¸¥ó¥i¥H®e¯Ç³\¦h­«½Æ©Ê½è°ªªº¤¸¥ó¡AÅܦ¨¤@­Ó¥i¥H­«½Æ§Q¥Îªºª«¥ó¡C ­º¥ý§Ú­Ì¨Ó¬Ý¨ì³Ì±`¨£ªº defs ¨Ò¤l¡G¡u­«½Æªº¹Ï§Î¡v¡A

¤U­±§Q¥Î defs ©w¸q¤F¤@­Ó¯x§Îªºªø¼eÃC¦â¡A¦A¨Ï¥Î use ¤¸¥ó§â¯x§Îªí²{¦bµe­±¤W¡A¦Ó use ¤¸¥ó¨ã¦³ x »P y ªº®y¼ÐÄݩʡA´N¥i¥H»´ÃPªº°µ¥X³\¦h¤£¦P¦ì¸mªº¯x§Î¡C

<defs>
  <rect id="rect1" width="100" height="50" x="10" y="10" fill="#c00"/>
</defs>
<use xlink:href="#rect1"/>
<use xlink:href="#rect1" x="110"/>
¤]¥i¥H±N g ¤¸¥ó ( ¸s²Õ ) ©ñ¦b defs ¤¸¥óùØÀY¡G
<defs>
    <g id="g1">
       <rect id="rect1" width="100" height="50" x="10" y="10" fill="#c00"/>
       <circle id="circle1" cx="30" cy="30" r="10" fill="#00c"/>
    </g>
</defs>
<use xlink:href="#g1"/>
<use xlink:href="#rect1" x="110"/>
<use xlink:href="#circle1" x="210"/>

Clipping ( °Åµô )

­n«Ø¥ß¤@­Ó Clipping ªº¹Ï§Î¡A­º¥ý­n¦b©w¸qÀɤº©ñ¤J<clipPath></clipPath>ªº¼ÐÅÒ¡A°O±o­n©ñ¤J id¡A³o¼Ë­n³Q°Åµôªº¹Ï§Î¤~¯à°÷¹ïÀ³¡C ±µµÛ¦b<clipPath></clipPath>ùØÀY©ñ¤J¤@¨Ç¹Ï§Î¡A³o¨Ç¹Ï§Î¥H¥~ªº³£·|³Q°Åµô¡C

¤U­±ªº½d¨Ò¡A¶ê§Î³Q¯x§Î°Åµô¤F¡A©Ò¥HÅܦ¨¥b¶ê§Î¤F¡C

<defs>
  <clipPath id="a1">
    <rect x="0" y="0" width="160" height="80" />
  </clipPath>
</defs>
<circle cx="80" cy="80" r="80" clip-path="url(#a1)" fill="lime" />

°Å¿è¸ô®|»P¹Ï¹³¤@°_ÁY©ñ

¨Æ¹ê¤W¡A<clipPath> ¤¸¥ó¥i¥H¥]§t¥ô·N¼Æ¶qªº°ò¥»§Îª¬¡]<rect>¡B<circle> µ¥¡^¡B<path> ¤¸¥ó¡A¬Æ¦Ü <text> ¤¸¥ó¡C

°²¦p SVG °Å¿è¸ô®|»P¹Ï¹³¤@°_ÁY©ñ¡A ¥²¶·±N clipPathUnits="objectBoundingBox" ²K¥[¨ì HTML ¤¤ªº clipPath¡A
¦Ó¥B SVG ¸ô®|­È¥²¶·¤¶©ó 0 ©M 1 ¤§¶¡¡C

<style>
.clip-svg {
  clip-path: url(#clip-svg);
}

<img src="Harry-Potter.jpg"  width="50%" height="50%" class="clip-svg">
<svg width="0" height="0">
  <defs>
    <clipPath id="myClip" clipPathUnits="objectBoundingBox">>
      <circle cx="0.5" cy="0.4" r="0.35"/>
    </clipPath>
  </defs>
</svg>

Clipping ( ¤å¦r°Åµô )

¥H¤U¬O¥Î§@°Å¤Á¸ô®|ªº¤@¬q¤å¥»ªº¥Ü¨Ò¡C
<defs>
    <clipPath id="Txt-clipPath">
        <text x="10" y="100" style="font-size: 40px"
        font-weight="bold">¤Ñ¤W©ú¤ë¥ú</text>
    </clipPath>
</defs>
<g id="g1" style="clip-path: url(#Txt-clipPath);">
    <circle cx="120" cy="120" r="100" fill="#34538b" />
    <rect x="0" y="0" width="120" height="180"
    style="fill:#cd0000;" />
</g>

SVG <text> «Ü»Åªº¤@ÂI¬O¥¦¥i¥H¨Ï¥Î¦Û©w¸q¦rÅéÅã¥Ü¡A´N¹³ HTML ¤å¥»¤@¼Ë¡C ¦b³o­Ó¨Ò¤l¤¤¡A¨Ï¥Î¤F¨Ó¦Û Google Web Fonts ªº Vollkorn ¦rÅé¡C ¨Ï¥Î textLength ÄݩʱN¤å¥»ªº¼e«×³]¸m¬°»P¹Ï¹³ªº¼e«×¬Û¦P¡A¨Ã¨Ï¥Î x ©M y §¤¼Ð©w¦ì¤å¥»¡C ª`·N³o¸Ìªº x ©M y §¤¼Ð¨M©w¤F¤å¥»¥ª¤U¨¤ªº¦ì¸m¡]©³³¡¥Nªí¤å¥»ªº°ò½u¡^¡C

°Ñ¦Ò¸ê®Æ:
css-svg-clipping
css3-svg-clip-path
image-pop-out-effect-with-svg-clip-path
using-clip-path-with-an-svg-defined-clippath
Apply effects to images with CSS's mask-image property

SVG ¸ô®| - <path>

SVG ¬O¦V¶q¹Ï¡A©Ò¦³ªºª«¥ó©M¤¸¥ó³£¬O¥Ñ Path ( ¸ô®| ) ©Ò²Õ¦¨¡C
©Ò¥H Path ´N¨ã¦³¬Û·í¦hªº«ü¥OÅý¨Ï¥ÎªÌ³]©w¡G
«ü¥O °Ñ¼Æ «ü¥O»¡©ú
M x y °_©lÂIªº x , y ®y¼Ð ( move to )
L x y¡@ ±q¥Ø«eÂIªº®y¼Ðµeª½½u¨ì«ü©wÂIªº x , y ®y¼Ð ( line to )
H x ±q¥Ø«eÂIªº®y¼Ðµe¤ô¥­ª½½u¨ì«ü©wªº x ¶b®y¼Ð ( horizontal line to )
V y ±q¥Ø«eÂIªº®y¼Ðµe««ª½½u¨ì«ü©wªº y ¶b®y¼Ð ( vertical line to )
C x1 y1 x2 y2 x y ±q¥Ø«eÂIªº®y¼Ðµe±ø¨©¯÷¦±½u¨ì«ü©wÂIªº x, y ®y¼Ð¡G¨ä¤¤ x1, y1 ¤Î x2, y2 ¬°±±¨îÂI ( curve )
S x2 y2 x y ±q¥Ø«eÂIªº®y¼Ðµe±ø¤Ï®gªº¨©¯÷¦±½u¨ì«ü©wÂIªº x, y ®y¼Ð¡G¨ä¤¤ x2, y2 ¬°¤Ï®gªº±±¨îÂI ( smooth curve )
Q x1 y1 x y ±q¥Ø«eÂIªº®y¼Ðµe±ø¤G¦¸¨©¯÷¦±½u¨ì«ü©wÂIªº x, y ®y¼Ð¡G¨ä¤¤ x1, y1 ¬°±±¨îÂI ( quadratic Bezier curve )
T x y ±q¥Ø«eÂIªº®y¼Ðµe±ø¤Ï®g¤G¦¸¨©¯÷¦±½u¨ì«ü©wÂIªº x, y ®y¼Ð¡G¥H«e¤@­Ó®y¼Ð¬°¤Ï®g±±¨îÂI( smooth quadratic Bezier curve )
A rx ry x-axis-rotation large-arc-flag sweep-flag x y ±q¥Ø«eÂIªº®y¼Ðµe­Ó¾ò¶ê§Î¨ì«ü©wÂIªº x, y ®y¼Ð¡G¨ä¤¤ rx, ry ¬°¾ò¶ê§Îªº x ¶b¤Î y ¶bªº¥b®|¡Ax-axis-rotation ¬O©·½u»P x ¶bªº±ÛÂਤ«×¡A large-arc-flag «h³]©w 1 ³Ì¤j¨¤«×ªº©·½u©Î¬O 0 ³Ì¤p¨¤«×ªº©·½u¡Asweep-flag ³]©w¤è¦V¬° 1 ¶¶®É°w¤è¦V©Î 0 °f®É°w¤è¦V (elliptical Arc )
Z ¡@ Ãö³¬¸ô®|¡A±N¥Ø«eÂIªº®y¼Ð»P²Ä¤@­ÓÂIªº®y¼Ð³s±µ°_¨Ó ( closepath )
ª`·N¡G¥H¤W©Ò¦³©R¥O¤]¥i¥H¥Î¤p¼g¦r¥Àªí¥Ü¡C ¤j¼gªí¥Üµ´¹ï©w¦ì¡A¤p¼gªí¥Ü¬Û¹ï©w¦ì¡C
§Q¥Î path µe¤T¨¤§Î
°_ÂI²¾¨ì 150 0¡Aµe½u¨ì 75 100¡Aµe½u¨ì 225 100¡A¦A¥Î Z Ãö³¬¸ô®|:
<svg height="120" width="300">
  <path d="M150 0 L75 100 L225 100 Z" style="fill:blue;" />
</svg>
§Q¥Î path µe¾ò¶ê§Î
A (Arc ©·½u) «ü¥O°Ñ¼Æ¦h¹F 7 ­Ó¡A¥H¤U´N¤@¤@¬°»¡©ú³o¨Ç°Ñ¼Æ:
A rx,ry x-axis-rotation large-arc-flag,sweep-flag  x,y
  1. rx ¡G ¾ò¶êªºªø¶b¥b®| ( ®Ú¾Ú¤£¦Pªº²×ÂI´«ºâ¦¨¤ñ¨Ò )
  2. ry ¡G ¾ò¶êªºµu¶b¥b®| ( ®Ú¾Ú¤£¦Pªº²×ÂI´«ºâ¦¨¤ñ¨Ò )
  3. x-axis-rotation ¡G ªø¶b»P x ¶bªº§¨¨¤
  4. large-arc-flag ¡G 1 ¬°¤j¨¤«×©·½u¡A0 ¬°¤p¨¤«×©·½u ( ¥²¶·¦³¤T­ÓÂI )
  5. sweep-flag ¡G 1 ¬°¶¶®É°w¤è¦V¡A0 ¬°°f®É°w¤è¦V
  6. x ¡G ²×ÂI x ®y¼Ð
  7. y ¡G ²×ÂI y ®y¼Ð
Ãö©ó A «ü¥O°Ñ¼Æªº¸Ô²Ó»¡©ú¡A¨£Path ¶i¶¥½g

¤U¦Cªº¸ô®|¤]¥i¥Î¥Hµe¾ò¶ê:

<path
    d="
    M cx cy
    m -rx, 0
    a rx,ry 30 1,0 (rx * 2),0
    a rx,ry 30 1,0 -(rx * 2),0
    "
/>
§Q¥Î path µe¶ê§Î
¸ô®|ªº«ü¥O A (Arc ©·½u) ¤]¥i¥Î¥Hµe¶ê:

cx cy ¬°¶ê¤ß§¤¼Ð¡Ar ¬°¥b®|¡A§Yrx ©M ry µ¥­È¬° r¡C

<path
    d="
    M cx cy
    m -r, 0
    a r,r 0 1,0 (r * 2),0
    a r,r 0 1,0 -(r * 2),0
    "
/>
¨©¶ëº¸(Bezier)¦±½u
¨©¶ëº¸(Bezier)¦±½u¥Î©ó¼ÒÀÀ¥i¥HµL­­ÁY©ñªº¥­·Æ¦±½u¡C ³q±`¡A¿ï¾Ü¨â­ÓºÝÂI©M¤@¨â­Ó±±¨îÂI¡C

¤G¦¸¨©¶ëº¸¦±½u°_ÂI©M²×ÂIªº¨©¯÷¦±½u¦@¥Î¦P¤@­Ó±±¨îÂI(50 50)¡A¥u»Ý­n¦³¨©¯÷±±¨îÂIªº®y¼Ð©M²×ÂI®y¼Ð§Y¥i¡C

<svg>
<path d="M0 0 Q30 120, 100 0" stroke="black" fill="none"/>
</svg>

¨ã¦³¨â­Ó±±¨îÂIªº¦±½uºÙ¬°¤T¦¸¨©¶ëº¸¦±½u:
·í¤¤ (40 40) ªí¥Ü²Ä¤@­Ó¨©¯÷¦±½uªº±±¨îÂI¡A(60 40) ªí¥Ü²Ä¤G­Ó¨©¯÷¦±½uªº±±¨îÂI¡A(100,0) «h¬O½u¬qªºµ²§ôÂI¡C
<svg>
<path d="M0 0 C40 40,90 60,100,0" stroke="black" fill="none"/>
</svg>
Ãè®g¨©¶ëº¸(Bezier)¦±½u
S ¥i¥H¦b­ì¥»ªºÂI«á¤è«Ø¥ß¤@­Ó±a¦³¨©¯÷¦±½u±±¨îÂIªºÂI¡AµM«á­ì¥»ªºÂI·|¥H¦P¼Ëªº±×²vÃè®g¤@­Ó¨©¯÷±±¨îÂI¡C
<svg>
<path d="M0 0 C40 40,60 40,100,0 S150 -40, 200 0"
           stroke="black" fill="none"/>
</svg>

ÅܧÎ

SVG ªº transform ´N¬O³o¤­­Ó¤èªk¡Gtranslate¡Bscale¡Brotate¡Bskew¡Bmatrix:

ÅܧΠ»yªk µ¥®Ä¯x°} »¡©ú
¦ì²¾ translate(tx,[ty]) matrix(1 0 0 1 tx ty) ¦b x ¶b©Î y ¶b¶i¦æ¦ì²¾
ÁY©ñ scale(sx,[sy]) matrix(sx 0 0 sy 0 0) scale ªº©ñ¤jÁY¤p°£¤F¼e«×©M°ª«×¡A³s¦P§¤¼Ð¤]·|¤@¨Ö©ñ¤jÁY¤p
±ÛÂà rotate(angle,[cx,cy]) matrix(cos(a) sin(a) -sin(a) cos(a) 0 0) rotate ¥i¥H±±¨î¹Ï§Îªº±ÛÂਤ«×¡A¶¶®É°w¬°¥¿¡A°f®É°w¬°­t¡C
±ÛÂà¶ê¤ßªº¹w³]­È¬° SVG ¾ã±iµe¥¬ªº¥ª¤W¨¤(0,0)¡A·íµM§Ú­Ì¤]¥i¥H¦Û­q¶ê¤ßªº®y¼Ð­È¡C
¶É±× skewX(angle)¡BskewY(angle) skewX¡Gmatrix(1 0 tan(a) 1 0 0)
skewY¡Gmatrix(1 tan(a) 0 1 0 0)
¤À§O¬O­n³]©w X »P Y ¤è¦Vªº¶É±×¨¤«×¡A¤£¹L»P scale ¦³ÂI¬Û¦Pªº¦a¤è¡A¨Ï¥Î skew ¤§«á¡A¤]¥²¶·¨Ï¥Î translate §â¦ì¸m½Õ¾ã¦^¨Ó¤~¥i¥H
³Æµù:¤¤¬A¸¹¬°¤£¬O¥²¶·ªº­È¡C

¨ÒÃD: ¯x§Î¥H°f®É°w±ÛÂà20«×¡C
<rect fill="none" width="60" height="60" x="50" y="50" stroke="#000" stroke-width="2" />
<rect fill="#c00" width="60" height="60" x="50" y="50" transform="rotate(-20,50,50)" />
  
¨ÒÃD: ¯x§Î¥H¶¶®É°w¶É±×50«×¡C
<rect fill="none" width="60" height="60" x="50" y="50"
    stroke="#000" stroke-width="2" />
<rect fill="#c00" width="60" height="60" x="50" y="50"
    transform="skewX(50) translate(-60)" />
Ãö©ó¯x°}ÅܧΪº¸Ô²Ó»¡¡A½Ð°Ñ¦Òtransform-matrix

SVG ´yÃä(stroke)ÄÝ©Ê

stroke Äݩʩw¸q¤¸¥óªº½u±ø¡B¤å¥»©Î½ü¹øªºÃC¦â¡G
<svg height="80" width="300">
  <g fill="none">
    <path stroke="red" d="M5 20 l215 0" />
    <path stroke="black" d="M5 40 l215 0" />
    <path stroke="blue" d="M5 60 l215 0" />
  </g>
</svg>
stroke ¤­­Ó³]©w
  • stroke ¡GÃ䮨ªºÃC¦â
  • stroke-width¡GÃ䮨ªº¼e«×
  • stroke-linecap¡GÃ䮨ºÝÂIªºÄÝ©Ê ( butt ( ¹w³] )¡Bsquare¡Bround )
  • stroke-linejoin¡GÃ䮨±µ¦X¦y¨¤ªºÄÝ©Ê ( miter ( ¹w³] )¡Bround¡Bbevel )
  • stroke-dasharray¡Gµê½u
°£¤FÃ䮨ªºÃC¦â©M¼e«×¡Astorke ³Ì­«­nªº¥u¦³³Ñ¤Uªº¤T­ÓÄݩʡA ­º¥ý§Ú­Ì¬Ý¨ìstroke-linecap©Mstroke-linejoin¡A¤À§O¥Nªí¤F¨â­ÓºÝÂIªºÄݩʡA¥H¤Î¨â±ø½u¬q¦y¨¤±µ¦X³BªºÄݩʡC
<polyline fill="none" stroke="#000000" stroke-width="10" points="83.678,119.133 113.376,89.434 143.075,119.133 "/>
<polyline fill="none" stroke="#000000" stroke-width="10" stroke-linecap="round" stroke-linejoin="round" points="193.546,119.133
    223.245,89.434 252.943,119.133 "/>
<polyline fill="none" stroke="#000000" stroke-width="10" stroke-linecap="square" stroke-linejoin="bevel" points="
    307.677,116.758 337.376,87.059 367.076,116.758 "/>

³Ì«á¤@­ÓÄݩʬOstroke-dasharray¡AùØÀYªº­È¬O¤@­Ó°}¦C¡A¥Nªí½u¬qªø«×»Pµê½u¶¡¹jªø«×ªº¥æ¿ù¼Æ¦r¡A³q±`¬O¨â­Ó¼Æ¦r¤@²Õ ( ªø«×©M¶¡¹j )¡A¦pªG¬O©_¼Æ¡A«h³Ì«á¼Æ¦r±µÄòªº¶¡¹j¡Aªø«×·|¥H²Ä¤@­Ó¼Æ¦r¬°¹w³]­È¡A¤U¤èªº¹Ï¤ù¥i¥H¬Ý¥X¤£¦P³]©w©Ò³y¦¨ªº®t²§¡G

<line fill="none" stroke="#000000" stroke-dasharray="2" x1="0" y1="0" x2="100" y2="0"/>
<line fill="none" stroke="#000000" stroke-dasharray="2,5" x1="0" y1="10" x2="100" y2="10"/>
<line fill="none" stroke="#000000" stroke-dasharray="2,5,3" x1="0" y1="20" x2="100" y2="20"/>
<line fill="none" stroke="#000000" stroke-dasharray="2,5,3,10" x1="0" y1="30" x2="100" y2="30"/>
<line fill="none" stroke="#000000" stroke-dasharray="2,5,3,10,5" x1="0" y1="40" x2="100" y2="40"/>
<line fill="none" stroke="#000000" stroke-dasharray="2,5,3,10,5,1" x1="0" y1="50" x2="100" y2="50"/>

µ§Ä²°¾²¾°Êµe

¨Ï¥Î path µe¥Xªº svg ¹Ï¡A¥[¤W°Êµeªº¼Ë¦¡¡A§Y¥i³vÂI°ÊºAµe¥X¡C

¨Ï¥Î @keyframes ©M stroke-dashoffset ÄݩʡA³Ð«Ø¶ñ¥R½u°Êµe¡C

#line {
    stroke-dasharray: 1;  // µê½u¶¡¹j: 1px
    animation-name: fill-line;
    animation-duration: 5s;
}

@keyframes fill-line {
    from {stroke-dashoffset: 1;    }    // µê½u°¾²¾: 1px
    to {  stroke-dashoffset: 0;    }
}

±N¦¹°Êµe¼Ë¦¡ line¡A²K¥[¨ì SVG ªº ¤¤¡A¦p¤U¡C
<svg id="visual" viewBox="0 0 1280 800" preserveAspectRatio="none" >
  <path id="line"
        d="M150 0 L75 100 L225 100 Z"
        pathLength="1" fill="none" stroke-linecap="round"  stroke="#9370db" stroke-width="3">
   </path>
 </svg>

¥Ü¨Ò: µe¤T¨¤§Î

±N¸ô®|«ü¥O´«¦¨¨ä¥L§Îª¬ªº«ü¥O¡A¦p:

¥Ü¨Ò: µe¶ê§Î
¥Ü¨Ò: µe¾ò¶ê§Î
¥Ü¨Ò: µe¤ß§Î
¥Ü¨Ò: µe½Ý°_¤j©æ«ü

°Ñ¦Òanimate-svg

SVG ¤å¥» - <text>

<svg height="60" width="200">
  <text x="0" y="15" fill="red" transform="rotate(30 20,40)">I love SVG</text>
</svg>
I love SVG
<text> ¤¸¥ó¥i¥H¨Ï¥Î <tspan> ¤¸¥ó±Æ¦C¦b¥ô·N¼Æ¶qªº¤l²Õ¤¤¡C ¨C­Ó <tspan> ¤¸¥ó¥i¥H¥]§t¤£¦Pªº®æ¦¡©M¦ì¸m¡C
<svg height="90" width="200">
  <text x="50" y="20" style="fill:red;">Several lines:
    <tspan x="50" y="45">First line.</tspan>
    <tspan x="50" y="70">Second line.</tspan>
  </text>
</svg>
Several lines: First line. Second line.

¸ô®|¤å¦r

±N¸ô®|©w¸q¦b <defs> ¥H«K­«½Æ¨Ï¥Î¡C¤§«á¦b <text> ¤º°¼³Ð«Ø <textPath>¡C
¨Ï¥Î xlink:href="#id" ¾É¤J¸ô®|¡A¤å¦r«K¥i¶¶µÛ¸ô®|Åã¥Ü¥X¨Ó¡C
<svg width="250" height="250">
  <defs>
    <path id="path" d="M20 30 Q40 5,60 30 T90 60 L200 80" />
  </defs>
  <text>
    <textPath xlink:href="#path" style="font-size:25px; fill:green">
      Hello World!
    </textPath>
  </text>
</svg>
Hello World!

SVG ÂoÃ褸¥ó

SVG ±è«×

±è«×¬O±q¤@ºØÃC¦â¨ì¥t¤@ºØÃC¦âªº¥­·Æ¹L´ç¡C ¦¹¥~¡A¥i¥H±N¦h­ÓÃC¦â¹L´çÀ³¥Î©ó¦P¤@¤¸¥ó¡C

SVG ¤¤¦³¨âºØ¥D­nªº±è«×Ãþ«¬¡G

  • ½u©Ê(Linear)
  • ®|¦V(Radial)
<svg height="150" width="400">
  <defs>
    <linearGradient id="grad3" x1="0%" y1="0%" x2="100%" y2="0%">
      <stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
      <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
    </linearGradient>
  </defs>
  <ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad3)" />
  <text fill="#ffffff" font-size="45" font-family="Verdana" x="150" y="86">
  SVG</text>
</svg>
SVG

¦p¦ó¨Ï¥Î SVG ¹Ï¹³

ºô­¶¤Þ¥Î SVG ¦³¤TºØ°µªk¡G
  • Object:
    • <embed src="../svg/happy.svg" ¡K>
    • <object data="../svg/happy.svg">
    • <iframe src="../svg/happy.svg" ¡K>
  • Inline: <svg>¡K</svg>
  • Image:
    • <img src="../svg/happy.svg" ¡K>
    • background: url('¡K')
       body {
         background-image: url(happy.svg);
       }
       

³o¬O¤°»òÄ_¥i¹Ú¡H

--> SVG ÂoÃ褸¥ó

--> SMIL °Êµe

°Ñ¦Ò¸ê®Æ