Jump to content
Search Community

Generating a timeline using Javascript object

JoePro test
Moderator Tag

Go to solution Solved by OSUblake,

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

Good Afternoon

 

i am trying to create a timeline based on a Javascript object, basically my object just refers to functions and custom labels that I want to generate within my timeline:

//object that I want to to use to create timeline with.
var chromeObj = {"box1()":"scene1",
                 "box2()":"scene2",
                 "box3()":"scene3",
                 "box4()":"scene4",
                 "box5()":"scene5"
                };

I am trying to create this type of timeline dynamically.

var master = new TimelineMax();

  master.add(box1(), "scene1")
  .addPause("+=0")
  .add(box2(), "scene2")
  .addPause("+=0")
  .add(box3(), "scene3")
  .addPause("+=0")
  .add(box4(), "scene4")
  .addPause("+=0")
  .add(box5(), "scene5")
  .addPause("+=0");
var master = new TimelineMax();

for (var key in chromeObj) {
  if (chromeObj.hasOwnProperty(key)) {
    
   master.add(key, chromeObj[key]);
   master.addPause("+=0");
  }
   
}

now this does don't work, more so due to my understanding of javascript but any help in correcting my logic would be most appreciative. my pen can be found here: 

 

Thanks again :)

See the Pen xOmwjP?editors=1111 by w9914420 (@w9914420) on CodePen

Link to comment
Share on other sites

Hi OSUblake

 

Many thanks for this, the only thing that I have noticed in your example is that that whilst you can play each tween continuously forwards or backwards. The issue that I get is that if i click forward once and then backwards once it will go forwards instead of backwards.

  • Like 1
Link to comment
Share on other sites

Hi OSUblake

 

Many thanks for this, the only thing that I have noticed in your example is that that whilst you can play each tween continuously forwards or backwards. The issue that I get is that if i click forward once and then backwards once it will go forwards instead of backwards.

 

Oops. Noob mistake. index++ and index-- should be ++index and --index. It's fixed now.

See the Pen zBXraO?editors=0010 by osublake (@osublake) on CodePen

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