Jump to content
Search Community

How to add stagger to scrollTrigger elements that are side by side

14136_1494126593 test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I have a simple demo with a few elements that are inside a grid and currently they all appear at the same time. I would like the boxes inside the box-group animate in one by one. I tried adding "stagger: 0.5", but obviously it's not working. What is the proper way to do this?

 

See the Pen OJdywRa by planetgrafix (@planetgrafix) on CodePen

Link to comment
Share on other sites

Hi,

 

One thing that can give you issues is that in your codepen demo you are using really old versions of GSAP and ScrollTrigger, always use the latest versions.

 

Regarding the order, actually ScrollTrigger is doing exactly what it should. Keep in mind that if you have a width that only fits six elements, you'll have (based on your demo) two rows, one with six elements and another with two. As soon as the elements with the class hit the trigger point, they are put into an array and animated based on the instructions you pass in the callbacks. If you scroll really slow and stop when just the first row appears everything will work as you expect, only the first row will show and the second one will show once those elements pass the trigger point. But if you scroll a bit more you'll see that the first and seventh element will animate in at the same time. That is totally expected since both elements passed the start trigger point almost at the same time. See the issue here? This is just because you are expecting this to behave in a different way, nothing more.

 

If you want your boxes inside a group to animate in the order they are present in the DOM, then ScrollTrigger Batch might not be the best alternative, just a regular stagger animation using a regular ScrollTrigger instance and specific selectors for each type of box.

 

Here is a fork of the last demo:

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

 

Hopefully this helps.
Happy Tweening!

Link to comment
Share on other sites

Thank you! That's very helpful, it made me understand better how defining the trigger works! I appreciate your support.

 

Thanks for pointing out that it wasn't the latest version of GSAP. I just added the one that came by default in Codepen - looks like they are linking to an older version.

 

EDIT: I just checked closer and unfortunately there is still an issue. As I scroll down, the boxes that are outside the group disappear as soon as the ones inside group start to appear.

 

 

 

Link to comment
Share on other sites

  • Solution
8 hours ago, 14136_1494126593 said:

EDIT: I just checked closer and unfortunately there is still an issue. As I scroll down, the boxes that are outside the group disappear as soon as the ones inside group start to appear.

Yeah, that's because you wanted completely different behavior for the ones in the group than the ones outside the group, so I just focused on animating those. You can just handle the other ones the same as you did before: 

See the Pen ExrPWxw?editors=1010 by GreenSock (@GreenSock) on CodePen

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