Jump to content
Search Community

ScrollTrigger | toggleClass for multiple Elements but only one should get the class

ainzon test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi,

 

I try to "reveal" sentences while scrolling down. That works so far and I played around with batch and timeline but I could not figure out how to "reveal only" one sentence at a time (and not two or three together). 

 

Additional idea: If a sentence is "active" - could I "pretend" a scrolling of 100px so the "active" sentence is longer "active"?

 

Thanks for any help and Ideas...

See the Pen rNvzbGb by boris-andraschko (@boris-andraschko) on CodePen

Link to comment
Share on other sites

Hi Rodrigo,

 

thank you very much for your answer. I played around with your solution to understand what you where doing.

 

So far it is clear. Just a question:

The if-statement in the forEach is not really necessary - it´s just because otherwise the first index would be -1 (there is no element before the first one) which would be wrong - ist that right or do I miss a point?

 

But thanks anyway - it works! :)

Link to comment
Share on other sites

1 hour ago, ainzon said:

The if-statement in the forEach is not really necessary - it´s just because otherwise the first index would be -1 (there is no element before the first one) which would be wrong - ist that right or do I miss a point?

 

If you remove the statement you'll get an error "GSAP target undefined not found" and depending on your setup this will or will not run your code, so it may be necessary and it is always better to write code that doesn't have errors in it. 

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

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