Jump to content
Search Community

Detect when a series of separate tweens are done

ryan_brwn test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

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

  • Solution

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

  • Like 4
Link to comment
Share on other sites

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. 

  • Like 1
Link to comment
Share on other sites

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

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...