Jump to content
GreenSock

PointC

jQuery each with delay - call next timeline when all are done

Recommended Posts

I've managed to confuse myself today. :)

 

 

I have a group of 5 elements that all do something a bit different based on their index as well as an index based delayed start. So far no problem - jQuery's each method works fine for that. I have more animations that I want to play after the last 'each' timeline has finished though.

 

 

I'm having trouble figuring out the best way to make sure the last 'each' timeline is finished before calling the function with the next timeline. I currently have the function call on the 'each' timelines, but that's obviously not right because it will be called 5 times. 

 

 

Should I be creating a master timeline from the 5 'each' timelines and calling the function at the end of that master? or is jQuery's each method not the best choice here? Should I be using a regular loop and creating those 5 timelines? What's the easiest way to make this happen?

 

 

Thanks.

 

See the Pen MyVoaE by PointC (@PointC) on CodePen

Link to comment
Share on other sites

there are many ways with same results , but maybe something like this 

if(i==$boxes.length-1) tl.vars.onComplete = part2 ;

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

  • Like 3
Link to comment
Share on other sites

Good grief!  I knew I just read that answer not too long ago, but couldn't remember which post it was. 

 

I even searched the forum - not sure how I missed that.

 

I even got some sleep last night so I have no excuse.

 

Blake schools the new moderator. :-P  

 

Edit - just saw your post Diaco. I like that too. Thanks much.

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

You can do the delay execution of a function using the settimeout & setinterval which are timer method of javascript. So you can apply 5 seconds delay on you animation with

setTimeout(function(){ //your logic }, 2000);

 

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