Jump to content
Search Community

Help Animating multple elements that have the same class name

potters_bluff test
Moderator Tag

Recommended Posts

Hello, I have been searching for a while, and trying different configurations for a solution to this problem, but just can't get it working.

 

I'm trying to run the same timeline (that has a class of .fade-wrap) each time it/any enters the viewport. As you will see in the CodePen, I have seen in other examples to wrap code with a foreach like:

 

const fadeSections = gsap.utils.toArray(".fade-wrap");
fadeSections.forEach((fadeSection) => {

 

animation code here

 

});

 

But it still runs the timeline on both as soon as the first one enters the viewport. I'm sure this is a simple fix, but I just cannot get it! Any help is greatly appreciated!

 

See the Pen rNeZrPp by rhilton (@rhilton) on CodePen

Link to comment
Share on other sites

  • potters_bluff changed the title to Help Animating multple elements that have the same class name
19 minutes ago, ZachSaucier said:

Hey potters_bluff and welcome to the GreenSock forums. Thanks for the clear demo!

 

You're making one of the most common ScrollTrigger mistakes: using a generic target when you want to use a more specific one. Just switch out trigger: ".fade-wrap", with trigger: fadeSection, and you'll be good to go!

Hmm, still doing the same behavior after switching the trigger line... I updated that pen, you can check it out.

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