Stefanp Posted June 11, 2023 Share Posted June 11, 2023 Hi, The default behavior of a stagger is that it will tween the objects one by one (like shown in the codepen). Is it also possible to use a single tween to stagger in pairs of N. For example, tween the first two elements together, then the next two elements etc. etc. I have a thousand elements and I want to move them in little groups around the screen. Thanks! See the Pen RwqPZZg by stefanpullen (@stefanpullen) on CodePen Link to comment Share on other sites More sharing options...
mvaneijgen Posted June 11, 2023 Share Posted June 11, 2023 Here is a way of doing it, I'm trying out some more options if I find any I post back here. See the Pen qBQdPWm by mvaneijgen (@mvaneijgen) on CodePen 3 Link to comment Share on other sites More sharing options...
Stefanp Posted June 11, 2023 Author Share Posted June 11, 2023 Nice solution. However, in my case, I'm actually tweening an array of objects. So I won't be able to utilize the nth-child css method. But at least now I know i need to fiddle around with constructing a filter for the selector Link to comment Share on other sites More sharing options...
Cassie Posted June 11, 2023 Share Posted June 11, 2023 Or... From the docs - you can create a stagger function gsap.to(".box", { y: 100, stagger: function(index, target, list) { // your custom logic here. Return the delay from the start (not between each) return index * 0.1; } }); Quote Only use this if you need to run custom logic for distributing the staggers. The function gets called once for each target/element in the Array and should return the total delay from the starting position (not the amount of delay from the previous tween's start time). The function receives the following parameters: index [Integer] - The index value from the list. target [Object] - The target in the list at that index value. list [Array | NodeList] - The targets array (or NodeList). 2 Link to comment Share on other sites More sharing options...
Solution GreenSock Posted June 12, 2023 Solution Share Posted June 12, 2023 For example... See the Pen YzRXjYK by GreenSock (@GreenSock) on CodePen 5 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now