Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
panoonan

Repeatable in viewport animations with scrollTrigger

Go to solution Solved by Cassie,

Recommended Posts

Hello, all. I am working on a site where there are various elements that I want to have a repeatable behavior on their entering of the viewport. For example, each section has text that needs to turn red once it is visible in the viewport as you scroll. I have used the basic example from the docs and it works as expected with the triggering event causing the text to change. The issue is that the trigger seems to then affect EVERY instance. So instead of scrolling and seeing the text change, after the first triggering, all of ".go-red" elements have completed their tween.

 

gsap.to(".go-red", 1.5, {
  scrollTrigger: ".go-red",
  color: "red"
});

 

I am sure there is a simple way to do this that doesn't involve id based triggering but it is stumping me. Any help is appreciated.

See the Pen MWvwBPQ by panoonan (@panoonan) on CodePen

Link to comment
Share on other sites

  • Solution

Hey there welcome to the forums!

This is an easy thing to get confused by. You're looking for a loop.

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


 

This article is a good read if you want to avoid common mistakes

 

  • Like 4
Link to comment
Share on other sites

I should have started with the "are you a bonehead?" article!

 

Thank you so much. This is entirely what I was after!

  • Haha 2
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.
×