2016-11-30 30 views
2

これは初めてSVGを使用していて、アニメーション化された線グラフを矢印で作成できるかどうかを知りたいと思っています。矢印のないアニメーション線グラフ、矢印のないアニメーション線グラフ、矢印付きアニメーション直線の複数の例が見つかりましたが、正確には私が探しているものではありません。以下に私が演奏してきたいくつかのcodepenの例を添付しました。これが可能かどうか誰にも知っていますか?大変感謝しています!SVGアニメーショングラフの矢印

  1. アニメーションライン欠落している矢印(ニーズは矢印): http://codepen.io/alexandraleigh/pen/jVaObd

    # HTML 
    <div class="graph__wrapper"> 
        <svg width="315px" height="107px" viewBox="0 0 315 107" version="1.1"> 
        <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> 
         <path d="M2.10546875,95.75 L40.5546875,68.3476562 L55.2109375,81.1796875 L65.2148437,76.3945312 L96.1835937,86.8320312 L131.023438,19.9414062 L142.15625,23.7226562 L183.605469,2.1953125 L211.007812,22.3320312 L234.320312,71.5664062 L234.667969,83.0039062 L244.019531,83.0039062 L247.105469,88.8320312 L312.695312,104.839844" id="Path-1" stroke="white" stroke-width="4" sketch:type="MSShapeGroup" class="path"></path> 
        </g> 
        </svg> 
    </div> 
    
    
    # CSS(Less) 
    
    @import "lesshat"; 
    
    @darkgrey:   #303030; 
    
    *{ 
        box-sizing: border-box; 
    } 
    
    body{ 
        background: @darkgrey; 
    } 
    
    .graph__wrapper{ 
        width: 400px; 
        margin: 30px auto; 
        position: relative; 
    
        svg{ 
        position: absolute; 
        margin: 36px 0px 0px 15px; 
        } 
    } 
    
    .path { 
        stroke-dasharray: 1000; 
        stroke-dashoffset: 1000; 
        animation: dash 3s ease-in forwards; 
        animation-iteration-count: 1; 
        animation-delay: 1s; 
    } 
    
    @keyframes dash { 
        to { 
        stroke-dashoffset: 0; 
        } 
    } 
    
    .description{ 
        font-family: "Roboto"; 
        color:lighten(@darkgrey, 50%); 
        text-align: center; 
        margin: 40px 0px; 
    } 
    
  2. アニメーションが矢印の直線(パス上の複数のポイントで停止する必要があります)

    http://codepen.io/alexandraleigh/pen/yVPYrY

  3. I #1から#2までのパス記述を追加しようとしましたが、最終的なグラフがあり、アニメーションはありません: http://codepen.io/alexandraleigh/pen/pNdgWR

  4. 私も#1〜#2から矢印マーカーを追加しようとしたが、矢印がアニメーション化されていません。 http://codepen.io/alexandraleigh/pen/aBVdVY

私はまた、http://snapsvg.io/としてプラグインを使用するオープンなんだけど、私の状況を助ける実用的な例は見ていない。

+0

:-(これはhttp://stackoverflow.com/questions/40864442/svg-progressbar-の重複のように思えるあなたは遅かれ早かれいずれかの方法であなたのコードを書き換える必要がありますアニメーションとスタートサークル/ 40865930より多かれ少なかれ。円の代わりに三角形を使用したい場合を除きます。 –

答えて

2

これは、オフセットモーション(古い構文:モーションパス)で行うことができます。 これは非常に実験的な機能であることにご注意ください。現在のところ、Chromeでのみ動作します。 ...それは、現在、クロムにどのような作品ですが、それはすぐに新しいsystaxに切り替わりますよう、私はここでは「古い」構文を使用するポイントにもっと

* { 
 
    box-sizing: border-box; 
 
} 
 
body { 
 
    background: #303030; 
 
} 
 
.graph__wrapper { 
 
    width: 400px; 
 
    margin: 30px auto; 
 
    position: relative; 
 
    svg { 
 
    position: absolute; 
 
    margin: 36px 0px 0px 15px; 
 
    } 
 
} 
 
.path { 
 
    stroke-dasharray: 428; 
 
    stroke-dashoffset: 428; 
 
    animation: dash 3s ease-in forwards; 
 
    animation-iteration-count: 1; 
 
    animation-delay: 1s; 
 
} 
 
@keyframes dash { 
 
    to { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
@keyframes pm { 
 
    from { 
 
    motion-offset: 0%; 
 
    } 
 
    to { 
 
    motion-offset: 100% 
 
    } 
 
} 
 
#arrow { 
 
    animation: pm 3s ease-in forwards; 
 
    animation-iteration-count: 1; 
 
    animation-delay: 1s; 
 
    motion-path: path('M2.10546875,95.75 L40.5546875,68.3476562 L55.2109375,81.1796875 L65.2148437,76.3945312 L96.1835937,86.8320312 L131.023438,19.9414062 L142.15625,23.7226562 L183.605469,2.1953125 L211.007812,22.3320312 L234.320312,71.5664062 L234.667969,83.0039062 L244.019531,83.0039062 L247.105469,88.8320312 L312.695312,104.839844'); 
 
    motion-rotation: auto; 
 
    motion-anchor: center; 
 
} 
 
.description { 
 
    font-family: "Roboto"; 
 
    color: lighten(@darkgrey, 50%); 
 
    text-align: center; 
 
    margin: 40px 0px; 
 
}
<div class="graph__wrapper"> 
 
    <svg width="315px" height="107px" viewBox="0 0 315 107" version="1.1" style="overflow:visible"> 
 
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> 
 
     <path d="M2.10546875,95.75 L40.5546875,68.3476562 L55.2109375,81.1796875 L65.2148437,76.3945312 L96.1835937,86.8320312 L131.023438,19.9414062 L142.15625,23.7226562 L183.605469,2.1953125 L211.007812,22.3320312 L234.320312,71.5664062 L234.667969,83.0039062 L244.019531,83.0039062 L247.105469,88.8320312 L312.695312,104.839844" 
 
     id="Path-1" stroke="white" stroke-width="4" sketch:type="MSShapeGroup" class="path"></path> 
 

 

 

 
     <polyline id="arrow" points="0,-5 10,0 0,5 1,0" fill="white" /> 
 

 
    </g> 
 
    </svg> 
 
</div>

あなたも行うことができますこれはanimateMotionとなりますが、すぐにsvgアニメーションが無効になります。

* { 
 
    box-sizing: border-box; 
 
} 
 
body { 
 
    background: #303030; 
 
} 
 
.graph__wrapper { 
 
    width: 400px; 
 
    margin: 30px auto; 
 
    position: relative; 
 
    svg { 
 
    position: absolute; 
 
    margin: 36px 0px 0px 15px; 
 
    } 
 
} 
 
.path { 
 
    stroke-dasharray: 428; 
 
    stroke-dashoffset: 428; 
 
    animation: dash 3s linear forwards; 
 
    animation-iteration-count: 1; 
 
    animation-delay: 1s; 
 
} 
 
@keyframes dash { 
 
    to { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.description { 
 
    font-family: "Roboto"; 
 
    color: lighten(@darkgrey, 50%); 
 
    text-align: center; 
 
    margin: 40px 0px; 
 
}
<div class="graph__wrapper"> 
 
    <svg width="315px" height="107px" viewBox="0 0 315 107" version="1.1" style="overflow:visible"> 
 
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> 
 
     <path d="M2.10546875,95.75 L40.5546875,68.3476562 L55.2109375,81.1796875 L65.2148437,76.3945312 L96.1835937,86.8320312 L131.023438,19.9414062 L142.15625,23.7226562 L183.605469,2.1953125 L211.007812,22.3320312 L234.320312,71.5664062 L234.667969,83.0039062 L244.019531,83.0039062 L247.105469,88.8320312 L312.695312,104.839844" 
 
     id="Path-1" stroke="white" stroke-width="4" sketch:type="MSShapeGroup" class="path"></path> 
 

 

 

 
     <polyline id="arrow" points="0,-5 10,0 0,5 1,0" fill="white"> 
 
     <animateMotion rotate="auto" begin="1s" dur="3s" repeatCount="1" fill="freeze"> 
 
      <mpath xlink:href="#Path-1" /> 
 
     </animateMotion> 
 
     </polyline> 
 

 
    </g> 
 
    </svg> 
 
</div>