Sun Devil
Sun Devil

Reputation: 29

Animate SVG with animateTransform

Trying to animate an SVG element with the skewX. It works, however, not exactly the way I want it to.

I tried with transform-origin but it didn't work. Any ideas how to solve this mystery?

<svg xmlns="http://www.w3.org/2000/svg" width="102" height="102" viewBox="-50 -50 102 102">
  <g>

    <rect width="10%" height="50%"
    style="fill:none; stroke:red; stroke-with:3;">

    <animateTransform
      attributeName="transform"
      attributeType="XML"
      type="skewX"
      from="0"
      to="-20"
      begin="0.5s"
      dur="0.2s"
      repeatCount="1"
      fill="freeze"
      id="fallen"/>

    </rect>
  </g>
</svg>

Upvotes: 0

Views: 721

Answers (1)

Robert Longson
Robert Longson

Reputation: 124059

Use another transform to move the whole thing to the right at the same time as the bottom moves left.

<svg xmlns="http://www.w3.org/2000/svg" width="102" height="102" viewBox="-50 -50 102 102">
  <g>

    <rect width="10%" height="50%"
    style="fill:none; stroke:red; stroke-with:3;">

    <animateTransform
      attributeName="transform"
      attributeType="XML"
      type="skewX"
      from="0"
      to="-20"
      begin="0.5s"
      dur="0.2s"
      repeatCount="1"
      fill="freeze"
      id="fallen"/>
   <animateTransform
      attributeName="transform"
      attributeType="XML"
      type="translate"
      from="0"
      to="20"
      begin="0.5s"
      dur="0.2s"
      repeatCount="1"
      fill="freeze"
      additive="sum"/>

    </rect>
  </g>
</svg>

Upvotes: 2

Related Questions