Jump to content
Search Community

tween at same time

court 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

Hi Court,

 

Sure, but there are some things you missed.

 

TimelineLite does not have the repeat method, for that you should use TimelineMax. Also you forgot to wrap the repeat var between curly brackets. The vars passed to the constructor is an object, so it has be in that particular syntax.

 

Finally the add() method has a position parameter, which allows you to set the time or label you want that particular tween to be played. This could be absolute or relative, please take a look at the API reference to find out more.

 

Your code should be like this:

function group() {
  var tl = new TimelineMax({repeat:-1});
  var time = 2.5;
  var redBox = DocById("redBox");
  var blueBox = DocById("blueBox");

  //after the tween a zero value is added indicating that this particular
  //tween should start at the time 0
  tl.add(TweenLite.to(redBox, time, {left:  "50px", top: "0px", ease:"Linear.easeNone" }),0);
  tl.add(TweenLite.to(blueBox, time, {left:  "50px", top: "0px", ease:"Linear.easeNone" }),0);
}

function DocById(id) {
  return document.getElementById(id);
}

group();

Rodrigo.

  • Like 3
Link to comment
Share on other sites

Hi Court,

 

Sure, but there are some things you missed.

 

TimelineLite does not have the repeat method, for that you should use TimelineMax. Also you forgot to wrap the repeat var between curly brackets. The vars passed to the constructor is an object, so it has be in that particular syntax.

 

Finally the add() method has a position parameter, which allows you to set the time or label you want that particular tween to be played. This could be absolute or relative, please take a look at the API reference to find out more.

 

Your code should be like this:

function group() {
  var tl = new TimelineMax({repeat:-1});
  var time = 2.5;
  var redBox = DocById("redBox");
  var blueBox = DocById("blueBox");

  //after the tween a zero value is added indicating that this particular
  //tween should start at the time 0
  tl.add(TweenLite.to(redBox, time, {left:  "50px", top: "0px", ease:"Linear.easeNone" }),0);
  tl.add(TweenLite.to(blueBox, time, {left:  "50px", top: "0px", ease:"Linear.easeNone" }),0);
}

function DocById(id) {
  return document.getElementById(id);
}

group();

Rodrigo.

Success, thanks!

Link to comment
Share on other sites

Yup, Rodrigo is exactly right.

 

In addition, you can make your code more concise by using the to() method instead of add()

 

tl.to(redBox, time, {left:50, top:0, ease:Linear.easeNone})
  .to(blueBox, time, {left:50, top:0, ease:Linear.easeNone},0);

.to() creates a TweenLite tween. add() is useful for adding TweenMax tweens (if you need repeating or other features of TweenMax tweens), timelines, labels or callbacks.

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