Jump to content
Search Community

From animation and scrolltrigger referencing the same element

Zoker test
Moderator Tag

Go to solution Solved by mikel,

Recommended Posts

Hi there,

 

I want to use a fade in animation on multiple elements bound to a scrollTrigger.

My current code looks like this:

gsap.from('.animation-fadein', {
    scrollTrigger: {
        trigger: '.animation-fadein',
        start: "center bottom",
        end: "bottom bottom",
        scrub: 0
    },
    opacity: 0
});

For one element this works fine, but when applying this class to multiple elements, it does not work anymore. 

I think the issue is, that the trigger does not use the same element as the from function.

 

I also tried to use something like this for the trigger property, but it does not seem to work. 

 

How can I bind the trigger to the same element as the from animation? Do I need to loop trough all elements?

See the Pen MWOywyr by Zoker (@Zoker) on CodePen

Link to comment
Share on other sites

  • Solution

Hey @Zoker,

 

try a separate scrollTrigger for each element:

 


gsap.utils.toArray('.fadein').forEach(function(part) {
 
  gsap.from(part, {
    scrollTrigger: {
      trigger: part,
      start: "center bottom",
      end: "bottom bottom",
      scrub: 0
    },
    opacity: 0
  });
  
});

 

Happy tweening ...

Mikel

  • Like 4
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...