Jump to content
GreenSock

Praney Behl

Convert CSS keyframes animation to GSAP-JS

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi there,

 

I am trying to implement some CSS keyframe animation to GSAP. Here is the keyframe animation:

@keyframes flyanimation {
  0% {
    opacity: 0;
    transform-origin: 0 100%;
    transform: scale(0, 0) rotate(360deg) translateY(-100%);
  }

  30% {
    transform-origin: 0 100%;
    transform: scale(0, 0) rotate(360deg) translateY(-100%);
  }

  100% {
    opacity: 1;
    transform-origin: 100% 100%;
    transform: scale(1, 1) rotate(0deg) translateY(0%);
  }
}

I am trying to figure out if there is a way to do it with the GSAP .fromTo() method or similar, if it is possible.

 

Any help will be greatly appreciated. 

 

Thanks,

Praney

Link to comment
Share on other sites

Hello Praney Behl,

 

Do you mean something like this:

See the Pen ovslz by jonathan (@jonathan) on CodePen

 

I'm not sure what your original CSS keyframe animation looks like but..

TweenMax.fromTo($("#box"), 2, 
                {
                  autoAlpha:0,
                  transformOrigin: "0 100%", 
                  scale:0, 
                  rotation:360,
                  y: "-100%"
                }, 
                {
                  autoAlpha:1,
                  transformOrigin: "100% 100%", 
                  scale:1, 
                  rotation:0,
                  y: "0%"
                }
);

:)

Link to comment
Share on other sites

Thanks Johnathan,

 

I did a bit of tweaking and this is the closest I could get:

 

See the Pen pImHz by praneybehl (@praneybehl) on CodePen

 

I think its pretty close to it. Its mind boggling how different the 2 are.

 

Praney :)

Link to comment
Share on other sites

It does look pretty close.. its hard for me to see the difference.

 

You can also feed GSAP the full transform property:

TweenMax.fromTo($("#box"), 2, 
      {
       autoAlpha:0,
       transformOrigin: "0 100%", 
       "transform": "scale(0, 0) rotate(360deg) translateY(-100%)"
      }, 
      {
       autoAlpha:1,
       transformOrigin: "100% 100%", 
       "transform": "scale(1, 1) rotate(0deg) translateY(0%)";
      }
);

And you can also pass force3D: true to use hardware acceleration for smoother animations.

 

:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×