【问题标题】:SVG rect animation direction bottom to topSVG rect 动画方向从下到上
【发布时间】:2019-10-14 00:38:03
【问题描述】:

我有以下 SVG 动画:

演示:https://codepen.io/anon/pen/xNJYGe

HTML:

<div class='batteryIcon'>
  <svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 668.3 1108.2">
    <rect class="power" x="100" y="150" width="470" height="880">
      <animate attributeName="height" values="0 ; 880" dur="2.5s" />
    </rect>
    <polygon class="st0" points="444.9,80.7 444.9,15.8 231.2,15.8 231.2,80.7 40.3,80.7 40.3,1080.8 629.3,1080.8 629.3,80.7 "/>
  </svg>
</div>

CSS:

.batteryIcon {
  svg {
    width: 50px;
    display: block;
    .st0 {
      fill: none;
      stroke: #adadad;
      stroke-width: 20;
      stroke-miterlimit: 5;
    }
    .power {
      fill: #06B67A;
    }
  }
}

我的问题是动画从_top 到bottom 而不是bottom to top。 我尝试通过 CSS 和内联属性transform 我的矩形,添加 rotatedirection 属性以及 keyPoints。到目前为止没有任何效果。

【问题讨论】:

    标签: animation svg


    【解决方案1】:

    只需将 y 值与高度同时设置动画即可。您想在 150 处完成 y,它需要更改 880,因此起始值必须是 880 + 150。

    svg {
      width: 50px;
      display: block;
    }
    .st0 {
      fill: none;
      stroke: #adadad;
      stroke-width: 20;
      stroke-miterlimit: 5;
    }
    .power {
      fill: #06B67A;
    }
    <div class='batteryIcon'>
      <svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 668.3 1108.2">
        <rect class="power" x="100" y="150" width="470" height="880">
          <animate attributeName="y" values="1030 ; 150" dur="2.5s" />
          <animate attributeName="height" values="0 ; 880" dur="2.5s" />
        </rect>
        <polygon class="st0" points="444.9,80.7 444.9,15.8 231.2,15.8 231.2,80.7 40.3,80.7 40.3,1080.8 629.3,1080.8 629.3,80.7 "/>
      </svg>
    </div>

    【讨论】:

      【解决方案2】:

      您可以使用polygon 并为points 属性设置动画,而不是使用rect 和动画height

      .batteryIcon svg {
        width: 50px;
        display: block;
      }
      .batteryIcon svg .st0 {
        fill: none;
        stroke: #adadad;
        stroke-width: 20;
        stroke-miterlimit: 5;
      }
      .batteryIcon svg .power {
        fill: #06B67A;
      }
      <div class='batteryIcon'>
            <svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 668.3 1108.2">
             <!--<rect class="power" x="100" y="150" width="470" height="880">
                <animate attributeName="height" values="0 ; 880" dur="2.5s" />
              </rect>-->
              
              <polygon points="100,1030 570,1030 570,150 100,150">
                <animate attributeName="points" values="100,1030 570,1030 570,1030 100,1030 ; 100,1030 570,1030 570,150 100,150" dur="2.5s" />
              </polygon>
            	<polygon class="st0" points="444.9,80.7 444.9,15.8 231.2,15.8 231.2,80.7 40.3,80.7 40.3,1080.8 629.3,1080.8 629.3,80.7 "/>
            </svg>
          </div>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-10
        • 2019-12-16
        • 2021-12-12
        • 2015-04-10
        • 2016-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多