Jump to content
Search Community

Uncaught Cannot add undefined into the timeline; it is not a tween, timeline, function, or string.

jollygreen test
Moderator Tag

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

I'm trying to create an infinite carousel with a stop button.  I got the following error on the console: "Uncaught Cannot add undefined into the timeline; it is not a tween, timeline, function, or string." Because of that my stop button doesn't work.  Would you know why I got this error?  Your help would be appreciated.  

 

See the Pen WmwYOW by jollygreen10 (@jollygreen10) on CodePen

 

See the Pen WmwYOW by jollygreen10 (@jollygreen10) on CodePen

Link to comment
Share on other sites

I don't quite understand what you're trying to do, but I definitely know why you're getting that error. You're calling add() on a TimelineMax and feeding in an array of null values because your slide() method doesn't return anything. In other words:

var test = slide(...); //<-- this doesn't return anything!
console.log(test); //null

 

Therefore, this:

TLentries.add([ slide(boxArray[0], boxArray[1], boxArray[2], boxArray[3], 0) ]); 

 

Is basically like doing this: 

TLentries.add([null]); 

 

Hence the error. It doesn't work to add null to a timeline ;)

 

If I knew what you were trying to accomplish, I might be able to offer a solution. I don't really understand why you're even using multiple timelines or maybe you're trying to nest things(?) But right now you're putting everything into the TLentry timeline anyway, so TLentries serves absolutely no purpose (other than to throw errors because you're adding null values to it). 

  • Like 1
Link to comment
Share on other sites

Ah, okay. Well, I think the way you've got things built makes the code a lot more cumbersome and animating "left" is far less performant (in most cases at least) than animating transforms like "x". So here's a quick rework I did for you: 

 

 

And it stops at 5 if you click "stop". 

 

Hopefully that gets you heading in the right direction. Happy tweening!

 

  • Like 3
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...