3

我发现下面的代码可以逐步用 css3 动画和 svg 画布画一条线。唯一的问题是我希望这条线被虚线,但我不确定如何修改它,更改 stroke-dasharray 似乎没有任何作用。谢谢!

<svg xmlns="http://www.w3.org/2000/svg" width="400px" height="300px">
  <style type="text/css">
    path {
      animation-name:animateDash;
      animation-duration:5s;
      animation-iteration-count:infinite;
    }
    @keyframes animateDash {
      from{stroke-dasharray:0,2305}
      to  {stroke-dasharray:2305,0}
    } 
  </style>
  <path d="m 7.1428565,220.9336 c 0,0 13.6660115,54.75386 218.5714335,51.42857 C 430.61971,269.03688 478.47682,99.194335 206.69537,110.78149 -65.086093,122.36866 45.497658,213.22607 210.28635,207.29759 375.07503,201.3691 429.75297,97.468925 207.14285,82.362175 -15.467268,67.255425 64.868608,160.66909 210,153.79075 c 145.13139,-6.87834 137.69998,-93.087405 11.42857,-99.999995 -126.271412,-6.9126 -150.382292,28.03248 -24.28571,35.71428 126.09659,7.6818 72.6601,-44.83727 -5.71429,-84.2857095"
    stroke-width="3" stroke-linecap="round" fill="none" stroke="black" stroke-dasharray="0,2305"/>
</svg>

http://jsfiddle.net/G4b6b/

4

1 回答 1

0

这是一篇可能对您有所帮助的文章:SVG Stroke Proprieties。更新的小提琴是Fiddle Updated。stroke-dasharray 的适当性是你想要玩的东西来达到你想要的结果。

@keyframes animateDash {
  from{stroke-dasharray:10,10}
  to  {stroke-dasharray:15,15}
}

如果那不是您想要的,并且您需要更多帮助,请给我更多详细信息。

希望能帮助到你。

    path {
      animation-name:animateDash;
      animation-duration:3s;
      animation-iteration-count:3;
    }
    @keyframes animateDash {
      from{stroke-dasharray:10,10}
      to  {stroke-dasharray:15,15}
    }
<svg xmlns="http://www.w3.org/2000/svg" width="400px" height="300px">
  <style type="text/css">
  </style>
  <path d="m 7.1428565,220.9336 c 0,0 13.6660115,54.75386 218.5714335,51.42857 C 430.61971,269.03688 478.47682,99.194335 206.69537,110.78149 -65.086093,122.36866 45.497658,213.22607 210.28635,207.29759 375.07503,201.3691 429.75297,97.468925 207.14285,82.362175 -15.467268,67.255425 64.868608,160.66909 210,153.79075 c 145.13139,-6.87834 137.69998,-93.087405 11.42857,-99.999995 -126.271412,-6.9126 -150.382292,28.03248 -24.28571,35.71428 126.09659,7.6818 72.6601,-44.83727 -5.71429,-84.2857095"
    stroke-width="3" stroke-linecap="round" fill="none" stroke="red" stroke-dasharray="10,10" d="M5 60 l215 0"/>
</svg>

于 2015-05-04T05:07:07.900 回答