Jump to content
GreenSock

velkas

Nested gsap.utils.toArray selector not working as expected

Go to solution Solved by GreenSock,

Recommended Posts

As you can see in the demo, I have duplicated sections with the same content structure and selectors. I'm attempting to use gsap.utils.toArray so I can iterate over the animated text but it seems to only be grabbing the first of each instance instead of three instances per section. Any ideas?

See the Pen zYjXGQb by connorhansen (@connorhansen) on CodePen

Link to comment
Share on other sites

I think the solution is to replace var scrollHeadings = gsap.utils.toArray(".animated-text", section); with var scrollHeadings = section.querySelectorAll(".animated-text");

Link to comment
Share on other sites

This is closer to what I'm trying to achieve but I'd like to chain the text animations while the parent section is pinned. In other words, I'd like to scroll through all animated text items before unpinning the parent section and scrolling to the next section. 

See the Pen gOzyawx?editors=1010 by connorhansen (@connorhansen) on CodePen

Link to comment
Share on other sites

  • Solution

You were just using a very old version of GSAP, before .toArray() accepted a "scope" parameter. Update to 3.11.3 and you'll be fine :)

 

I'm not sure exactly what effect you're going for, but here's a quick guess: 

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

  • Thanks 1
Link to comment
Share on other sites

Ahh thanks!! That's much closer to what I'm trying to achieve. I took it a step further but the alignment isn't ideal... should I use absolute positioning for the animated text so they are on top of each other? Ideally the text also snaps to prevent overscrolling.

See the Pen bGMJVYK?editors=1010 by connorhansen (@connorhansen) on CodePen

Link to comment
Share on other sites

Yep, definitely use absolute positioning to get your text in the correct spot. As for snapping, you'd need to calculate the math to find the right progress values where the text has "landed" (the snapping positions). You could feed an Array of those values into the snap property. 

  • Like 1
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.
×