Jump to content
Search Community

Possible to staggerTo with different properties for each element?

resting 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

Say I have 2 elements in .staggerTo(), is it possible to animate different properties for the 2 elements?

 

If not, is creating a different timeline the best solution?

 

The problem here is, I have a timeline1, that has a series of animations, but on the last animation, I want to  animate one element coming in on the left, and another coming in from the right.

 

If I were to create another timeline for the element coming from the right, I'll need to calculate the seconds it should start, which is what I'm trying to avoid.

 

Codepen example with 2 timelines, cause I'm not sure how to do it with staggerTo.

See the Pen GZNNqe by resting (@resting) on CodePen

Link to comment
Share on other sites

You can use cycle...

var tl = new TimelineMax()
  .staggerTo(["#foo", "#bar"], 1, { cycle: { x: [100, -100]}}, 0, "last");

But I'm not really sure I'm getting the trouble you were having with 2 timelines and calculating the time. You can animate different elements from the same timeline, and can start animations at the same time using a label. So the code above could be written like this.

var tl = new TimelineMax()
  .to("#foo", 1, { x:  100 }, "last")
  .to("#bar", 1, { x: -100 }, "last");

In my opinion, it's much easier to read and understand what is going on in the second example.

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