Aimack Posted December 5, 2022 Share Posted December 5, 2022 Thank you for helping, in advance. I've two questions. 1. The animation is starting even before I am using anim.play(). I suppose that this is because the anim.to is getting initiated before itself. But I can't solve this issue. 2. The animation is not smooth at all even after adding easing. When I am zooming in the browser, it is smoother but when at 100% zoom level, it is stuttering. See the Pen RwJERjP by Aimack (@Aimack) on CodePen Link to comment Share on other sites More sharing options...
Solution mvaneijgen Posted December 5, 2022 Solution Share Posted December 5, 2022 Hi @Aimack welcome to the forum! You could set your timeline to be paused initially, this way it will only play if you trigger it. The y property will animate in pixels by default, so you can just feed it a number instead of a string. I can't really see the stuttering you're talking about. You do however animate a really small animation (4 pixels) over a really long time (1 second), if you decrease the time it will feel a lot smoother. I've also add another property to your timeline called reversed: true, this way you can do the following in the click handler anim.reversed() ? anim.play() : anim.reverse(); if the timeline is reversed, play it or otherwise reverse it. A side note, but a really important one when working with GSAP (and CSS in general), never use transition: all; you never want to transition everything, in your case you just want to transition the background-color. Also if you have transitions on your elements and you want to animate them with GSAP this is not something that can work, in that case it is always better to remove the transitions from CSS and let GSAP handle them. Hope it helps and happy tweening! See the Pen NWzeRYO?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen 3 Link to comment Share on other sites More sharing options...
Aimack Posted December 6, 2022 Author Share Posted December 6, 2022 Thank you so much @mvaneijgen. Picked up a few things from your post. Today is my second day with GSAP, thoroughly enjoying the experience. 1 Link to comment Share on other sites More sharing options...
mvaneijgen Posted December 6, 2022 Share Posted December 6, 2022 Ha, cool to hear! Your code looks really clean for your first few days! Keep it up. 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