Jump to content
Search Community

Converting keyframes to JS animation with GSAP

danolrob test
Moderator Tag

Go to solution Solved by Rodrigo,

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

Hello everyone,

 

I am new to GSAP and I need your help to convert a CSS keyframe animation in a javascript one with GSAP.

 

@keyframes elliptical-anim {
   0% {
   transform: translate3d(0,150%, 0) rotate3d(0, 0, 1,0deg) translate3d(0,-150%, 0) rotate3d(0, 0, 1,0deg) scale3d(.1,.1,1);
}
20% {
   transform: translate3d(0,150%, 0) rotate3d(0, 0, 1,-72deg) translate3d(0,-150%, 0) rotate3d(0, 0, 1,72deg) scale3d(1,1,1);
}
96% {
   transform: translate3d(0,150%, 0) rotate3d(0, 0, 1,-359deg) translate3d(0,-150%, 0) rotate3d(0, 0, 1,359deg) scale3d(1,1,1);
}
100% {
   transform: translate3d(0,150%, 0) rotate3d(0, 0, 1,-359deg) translate3d(0,-150%, 0) rotate3d(0, 0, 1,359deg) scale3d(.3,.3,1);
}
}
 
I'm using the 3D version of the animations in order to force the hardware acceleration.
 
 
Thanks in advance for your help !

See the Pen yNKwEo by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi danolrob  :)

 

there are some ways to doing that , pls try these ways :

//method #1
TweenLite.fromTo("#ball",2,{scale:0,transformOrigin:"50% 150px"},{scale:1,rotation:-360})
TweenMax.to("#ball",0.05,{scale:0.3,repeat:1,yoyo:true,delay:1.9,transformOrigin:"50% 50%"})

//method #2
TweenMax.fromTo("#ball",2,{scale:0.2},{scale:1,bezier:{curviness:1.5,values:[{x:0,y:0},{x:-100,y:100},{x:0,y:200},{x:100,y:100},{x:0,y:0}]},ease:Power0.easeNone});
TweenMax.to("#ball",0.05,{scale:0.3,repeat:1,yoyo:true,delay:1.95});

if you need perfect circle path , i think that's better / easier to use BezierPlugin ( method #2 )

 

BezierPlugin Doc. : http://greensock.com/docs/#/HTML5/Plugins/BezierPlugin/

 

pls check this out : 

See the Pen oXqOoX by MAW (@MAW) on CodePen

 

btw , pls be sure that using last version of GSAP ( 1.17.0 ) , in your codepen , i see version 1.11.5  :blink:  <_<

  • Like 3
Link to comment
Share on other sites

Thank you very much for the prompt reply.

 

The second method is exactly what I was looking for, so I am definitely going to use the bezier plugin.

 

There is however one thing different from the keyframes :

 

I only need 400ms delay between the first and the second scale instruction (scale:0.2 and scale:1).

 

Thanks again !  :-P 

 

Edit : Typo.
 

Link to comment
Share on other sites

  • Solution

Hi,

 

In that case it would be better to use a Timeline and set the delays between the instances with the position parameter, like this:

var tl =  new TimelineLite();

tl
  .to("#ball",2,{bezier:{curviness:1.5,values:[{x:0,y:0},{x:-100,y:100},{x:0,y:200},{x:100,y:100},{x:0,y:0}]},ease:Power0.easeNone})
  .fromTo("#ball", 0.4, {scale:0.2}, {scale:1}, 0)
  .add(TweenMax.to("#ball",0.05,{scale:0.3,repeat:1,yoyo:true}), 1.9);
  • Like 2
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.
×
×
  • Create New...