Is there a way to add two amp-animations to a single div ?

269 Views Asked by At

So this is my code, in the body tag, as specified in the docs :

   <amp-animation layout="nodisplay" trigger="visibility">
    <script type="application/json">
        [
            {
                "selector": ".shape-3",
                "duration": 1000,
                "delay": 0,
                "keyframes": "buildInKeyframes",
                "fill": "both",
                "direction": "normal"
            },
            {
                "selector": ".shape-3",
                "duration": 1000,
                "delay": 1200,
                "keyframes": "buildOutKeyframes",
                "fill": "both",
                "direction": "normal"
            }

        ]
    </script>
    </amp-animation>

( In head tag i have the keyframes defined with tags style amp-custom ) I have a div with class="shape-3" and i want to animate it with the first animation, and after it finishes, animate with the second animation. The problem is that

1

There are 1 best solutions below

0
On

You can try using animation in the following way:

<amp-animation layout="nodisplay">
  <script type="application/json">
    {
      "selector": ".shape-3",
      "duration": "1s",
      "iterations": "1",
      "fill": "both",
      "direction": "alternate",
      "animations": [
        {
          "selector": ".target-class",
          "easing": "cubic-bezier(0,0,.21,1)",
          "keyframes": {
            "transform": "rotate(20deg)"
          }
        },
        {
          "delay": "1s",
          "easing": "cubic-bezier(0,0,.21,1)",
          "keyframes": {
            "transform": "rotate(30deg)"
          }
        }
      ]
    }
  </script>
</amp-animation>

Where the delay for the second animation is the time spent for first anim.