Jump to content
Search Community

Stagger elements across a fixed timeline

nthony test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hi,

 

Question: How can I run animations to for an exact period of time? Eg 2 seconds

- I see that I can use set duration(2), but this simply alters the timescale not the duration itself, so the player only runs for 2 seconds.

 

Question: How can I stagger a list of Dom Elements to be evenly distributed stagger starts ? 

- Complexity here is that each element can have a different animation applied.

- Can I use distribute() method to calculate positions?

 

Essentially the problem I am attempting to solve is - I have a list of Dom elements that I need to animate, each being staggered over a fixed time window. All animations should be completed within the specified time duration. 

Eg 10 elements need to be animated, and staggering each start, but all animations must finish within 2 seconds.

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Hi @nthony welcome to the forum!

 

What have you tried already? We love to see minimal demo's, that way we can see your thought proces and thus better help help you. 

 

The stagger can be a simple property, where you just feed it a number, this will then be the duration each stagger takes after the previous one, but it can be its own object to where you can specify it a lot of powerful features. Like amount: 

 

 

[Number]: The total amount of time (in seconds) that gets split among all the staggers. So if amount is 1 and there are 100 elements that stagger linearly, there would be 0.01 seconds between each sub-tween's start time. If you prefer to specify a certain amount of time between each tween, use the each property instead.

 

This seems like exactly what you're describing. From the docs https://greensock.com/docs/v3/Staggers

 

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, akapowl said:

 

Just adding a quick example:

 

With the duration of a tween being 0.5 seconds and a stagger amount of 1.5, you would have a total time of 2 seconds everytime, no matter how many elements you have.

 

 

 

 

 

Thanks for this quick demo showing this, this kind of what I need, except that each element needs to have its own animation defined.

 

I've been using effects to create different animations for different elements, but this may not be the best way.

 

Here is an example codepen showing different animations per element. I'm trying to evenly stagger all the starts across all elements and for the animation to complete in 2 seconds.

 

See the Pen gOjorxr by nthonymiller (@nthonymiller) on CodePen

 

 

Edited by nthony
Display incorrectly
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...