【问题标题】:Is there an SVG equivalent of CSS' animation-fill-mode: forwards?是否有相当于 CSS 的动画填充模式的 SVG:转发?
【发布时间】:2019-09-03 00:39:26
【问题描述】:

我想为形状设置动画并防止它们在起点处重置。

我想使用 animation-fill-mode:forwards;,但我不确定它是否适用以及在我的标签中放置它的位置。

Here 可以看到我的圆圈被重新定位在左上角,而我想让它停留在它的运动路径结束的地方,在六边形的顶点。

<!DOCTYPE HTML>
  <html>
    <body>
      <?xml version="1.0"?>
    <svg width="400" height="400" viewBox="0 0 200 200"
        xmlns="http://www.w3.org/2000/svg" version="1.1"
        xmlns:xlink="http://www.w3.org/1999/xlink" style="background:aquamarine">
        <style>
        path {
          animation-name:animateDash;
          animation-duration:5s;
          animation-iteration-count:once;
          animation-fill-mode:forwards;
        }
        @keyframes animateDash {
          from{stroke-dasharray:0,2305}
          to  {stroke-dasharray:2305,0}
        }
        </style>


        <circle cx="50%" cy="50%" r="1" fill="firebrick"  />

        <path id="theMotionPath" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="antiquewhite" fill="none" stroke-linecap="round" stroke-linejoin="round" />

        <path id="theMotionPath2" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="aqua" fill="none" style="transform-origin:50%;transform: rotate(120deg);" stroke-linecap="round" stroke-linejoin="round" />

        <path id="theMotionPath3" d="m 100,100 -3e-6,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="azure" fill="none" style="transform-origin:50%;transform: rotate(240deg);" stroke-linecap="round" stroke-linejoin="round" />

        <circle cx="0" cy="0" r="5" fill="#333333">
          <animateMotion dur="0.45s" repeatCount="once">
            <mpath xlink:href="#theMotionPath3"/>
          </animateMotion>
        </circle>

        <g style="transform-origin:50%;transform: rotate(120deg);">
          <circle cx="0" cy="0" r="5" fill="#333333">
            <animateMotion dur="0.45s" repeatCount="once">
              <mpath xlink:href="#theMotionPath3"/>
            </animateMotion>
          </circle>
        </g>

        <g style="transform-origin:50%;transform: rotate(240deg);">
          <circle cx="0" cy="0" r="5" fill="#333333">
            <animateMotion dur="0.45s" repeatCount="once">
              <mpath xlink:href="#theMotionPath3"/>
            </animateMotion>
          </circle>
        </g>

    </svg>
  </body>
</html>

【问题讨论】:

    标签: animation svg


    【解决方案1】:

    使用fill="freeze" 作为animateMotion 的属性,如下所示:

    <svg width="400" height="400" viewBox="0 0 200 200"
            xmlns="http://www.w3.org/2000/svg" version="1.1"
            xmlns:xlink="http://www.w3.org/1999/xlink" style="background:aquamarine">
    
    
    
            <circle cx="50%" cy="50%" r="1" fill="firebrick"  />
    
            <path id="theMotionPath" d="m 100,100 -0.000003,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="antiquewhite" fill="none" stroke-linecap="round" stroke-linejoin="round" />
    
            <path id="theMotionPath2" d="m 100,100 -0.000003,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="aqua" fill="none" style="transform-origin:50%;transform: rotate(120deg);" stroke-linecap="round" stroke-linejoin="round" />
    
            <path id="theMotionPath3" d="m 100,100 -0.000003,-52.916668 45.82718,26.458333 0,52.916665" stroke-width="5px" stroke="azure" fill="none" style="transform-origin:50%;transform: rotate(240deg);" stroke-linecap="round" stroke-linejoin="round" />
    
            <circle cx="0" cy="0" r="5" fill="#333333">
              <animateMotion dur="0.45s" repeatCount="once" fill="freeze">
                <mpath xlink:href="#theMotionPath3"/>
              </animateMotion>
            </circle>
    
            <g style="transform-origin:50%;transform: rotate(120deg);">
              <circle cx="0" cy="0" r="5" fill="#333333">
                <animateMotion dur="0.45s" repeatCount="once" fill="freeze">
                  <mpath xlink:href="#theMotionPath3"/>
                </animateMotion>
              </circle>
            </g>
    
            <g style="transform-origin:50%;transform: rotate(240deg);">
              <circle cx="0" cy="0" r="5" fill="#333333">
                <animateMotion dur="0.45s" repeatCount="once" fill="freeze">
                  <mpath xlink:href="#theMotionPath3"/>
                </animateMotion>
              </circle>
            </g>
    
        </svg>

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2014-09-26
      • 2013-01-23
      • 2012-09-17
      • 1970-01-01
      • 2017-08-30
      • 2019-11-10
      • 2018-05-20
      • 1970-01-01
      相关资源
      最近更新 更多