Evgeniia Posted February 1 Share Posted February 1 Hey everyone! I have an animation of swirling stars around the button. JS code creates each star with its own CSS animation. The issue of this code is that it adds new and new stylesheets in head code and it decreases perfomance speed. So I'm trying to recreate the same animation with GSAP library to avoid this adding new stylesheets into head code, but I don't get how is right to do. Could you help me, please? See the Pen ZEPxRgm by EvgeniiaShirshikova (@EvgeniiaShirshikova) on CodePen See the Pen jOJzKdZ by EvgeniiaShirshikova (@EvgeniiaShirshikova) on CodePen Link to comment Share on other sites More sharing options...
Solution GreenSock Posted February 1 Solution Share Posted February 1 Cool effect! Yeah, this is all very doable with GSAP but it's beyond the scope of help we can provide in these forums for free. The main issue I see is that your original CSS-based one uses a non-standard order-of-operation on the transforms. One of the very convenient things about GSAP is that it delivers a very consistent, predictable order of operation on each transform component. I see a few options to get the effect you want: Just use a generic object that contains the properties you need to animate (x, y, rotation, scale). Animate those and then use a simple onUpdate to set the element.style.transform with those updated values. This lets you use the exact same order of operation as in your original CSS demo. Or wrap each of your elements in a container. Animate the rotation of the container, and counter-rotate the nested element in the opposite direction so that it looks like it remains oriented properly, but you get the orbit effect. For the offset, just alter the "x" of the nested element. And scale the inner element too. So you're basically reproducing the order of operation via the nesting. I hope that helps! Link to comment Share on other sites More sharing options...
Evgeniia Posted February 1 Author Share Posted February 1 4 minutes ago, GreenSock said: Cool effect! Yeah, this is all very doable with GSAP but it's beyond the scope of help we can provide in these forums for free. The main issue I see is that your original CSS-based one uses a non-standard order-of-operation on the transforms. One of the very convenient things about GSAP is that it delivers a very consistent, predictable order of operation on each transform component. I see a few options to get the effect you want: Just use a generic object that contains the properties you need to animate (x, y, rotation, scale). Animate those and then use a simple onUpdate to set the element.style.transform with those updated values. This lets you use the exact same order of operation as in your original CSS demo. Or wrap each of your elements in a container. Animate the rotation of the container, and counter-rotate the nested element in the opposite direction so that it looks like it remains oriented properly, but you get the orbit effect. For the offset, just alter the "x" of the nested element. And scale the inner element too. So you're basically reproducing the order of operation via the nesting. I hope that helps! Thank you for your time! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now