Jump to content


Recursive callback onComplete - play random timelines at the end of each other

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi everyone!

I'm currently trying to create a function that plays a timeline, add to that a callback function that play another random timeline, with a callback to another etc.. (something like a recursion)

In example: In have some timelines (7/8) and I want to play them one after one completely random, endless. 
I really can't find any error, in my mind this can work but in real it doesn't. I works for the first one / two  iterations then it goes in a insanely loop


function playRoutes(){
  var randValue = Math.floor(Math.random() * (globeHandler.routes.length));
  var route = globeHandler.routes[randValue].timeline;
  route.timeline.eventCallback('onComplete', playRoutes);				



Here is the console.log o the random value, as you can see is called very fast.




Any idea?

Link to comment
Share on other sites

Hi @dghez


You probably need to restart your timeline. Calling play without a parameter just plays it from where it was, which is probably the end.



// or






  • Like 4
Link to comment
Share on other sites

And it looks like I'm a little late as this was already answered on slack.

  • Like 1
Link to comment
Share on other sites

6 hours ago, OSUblake said:

And it looks like I'm a little late as this was already answered on slack.

Yup. Thanks anyway ;-)

Actually after the slack discussion I forgot about this question.

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.