Jump to content
Search Community

Best way to add concurrent tweens?

jezmck test
Moderator Tag

Go to solution Solved by Dipscom,

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

When I have two tweens which I want to run concurrently, I've been taking the following approach (concatting a string for the `position`), but feel there must be a better way.

var tl = new TimelineLite({ paused: true });
var $box = jQuery(".box");
var duration = 2;

tl.add(TweenLite.to($box, duration, {
  ease: 'Bounce.easeOut',
  width: 100
}));

tl.add(TweenLite.to($box, duration, {
  // don't want bounce-ease on this property
  height: 300
}), '-=' + duration);

Any suggestions very welcome!

See the Pen bpYVpv by jezmck (@jezmck) on CodePen

Link to comment
Share on other sites

  • Solution

When I want more than one tween to start at the same point, I create a label for that point in time and use that as the position parameter:

tl.add("StartPoint");

tl.to($box, duration, {
ease: 'Bounce.easeOut',
width: 100
}, "StartPoint");

tl.to($box, duration, {
// don't want bounce-ease on this property
height: 300
}, "StartPoint");

Note that you can use convenience methods, like .to(), from(), etc, just like in TweenMax to build your timelines. You don't need to .add() each Tween in the Timeline.

 

Also, you can chain those methods. The bellow will produce the same results as the code above:

tl.add("StartPoint")
  .to($box, duration, {ease: 'Bounce.easeOut', width: 100}, "StartPoint")
  .to($box, duration, {height: 300}, "StartPoint");

Make sure you add ";" only in the last call.

  • Like 7
Link to comment
Share on other sites

Thanks Oscar.

 

I should have mentioned that the .add() method also accepts a position parameter, so, you can have a bunch of Tweens starting at the same time that overlaps another tween in the timeline.

tl.to(box, dur, {...})
.to(square, dur, {...})

.add("StartPoint", "-="+dur)
.to(rectangle, dur, {...}, "StartPoint")
.to(triangle, dur, {...}, "StartPoint");
  • Like 4
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...