ryan_brwn Posted July 6, 2023 Share Posted July 6, 2023 This might be a newb question but is there a way to detect when a series of separate tweens are done? Here's a minimal demo. I'd like to call tweensDone() when both tweens have finished. (FYI The object structure mirrors how I'm structuring things on a real project.) See the Pen 58126b861d0b181cf8c9f381e7092b7b?editors=0011 by ryankbrown (@ryankbrown) on CodePen Link to comment Share on other sites More sharing options...
Solution mvaneijgen Posted July 6, 2023 Solution Share Posted July 6, 2023 You've blocked the forking of your pens and I thus had to manually copy everything to a new pen to share my modifications. As soon as I have more then one animation my mind goes to a timeline, so also here. I've tweaked your moveBoxes() function to create a timeline and returned the tween in your move() logic which allows me to add those tweens to a timeline, which in turn gives me a onComplete (and all other callbacks) on the tweens. See the Pen rNQGagR by mvaneijgen (@mvaneijgen) on CodePen 4 Link to comment Share on other sites More sharing options...
ryan_brwn Posted July 6, 2023 Author Share Posted July 6, 2023 Ah that makes perfect sense and I think that's probably the route I'll end up going. I am still curious to see if there's a way to do this without creating a timeline. Any ideas? Link to comment Share on other sites More sharing options...
GreenSock Posted July 7, 2023 Share Posted July 7, 2023 Can you help us understand why you want to avoid using a timeline? There are many other ways you could do it, but probably none are as convenient and bullet-proof as putting stuff into a timeline. You could create individual tweens and then find the longest duration and add the onComplete for that one with eventCallback(). Or tack on a delayedCall() at the end that matches the longest duration. I'm not sure why you'd opt for anything other than the simple timeline solution though. 1 Link to comment Share on other sites More sharing options...
ryan_brwn Posted July 7, 2023 Author Share Posted July 7, 2023 Ah ok that makes perfect sense. I would explain why I was trying to avoid using a timeline but based on your answer it seems completely unnecessary. The way I had set up my project had me sort of binding gsap calls to individual objects that move but I realized I needed something to happen when the objects stopped moving. And being that I'm always learning something new about gsap I was just curious if there was a methodology or functionality in the library that would allow for that. Thanks for your help!! 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