Jump to content
Search Community

Conflict problem in fade in and fade out on scrolling

OrganicBlue test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi,

 

The issue is when you create the Timeline instance for each section. Basically when you animate something using a collection or array is ok but when it comes to ScrollTrigger's trigger element you can't use that and is quite obvious: Which one actually controls the animation? What happens if for some reason they overlap? See the problem?

 

In this case is better to loop through all the sections, create a single timeline for each and then add the animations of each section's children to the timeline:

const sections = gsap.utils.toArray(".section-scroll-fade");

sections.forEach((section) => {
  let scrollFadeElements = section.querySelectorAll(
    ".scroll-fade__group"
  );
  let scrollFadeLength = scrollFadeElements.length * 1000;
  let scrollFadeTL = gsap.timeline({
    scrollTrigger: {
      trigger: section,
      start: "top top",
      end: "+=" + scrollFadeLength,
      scrub: true,
      pin: true,
      id: "asd",
      markers: {
        indent: 150
      }
    }
  });
  scrollFadeElements.forEach((e) => {
    scrollFadeTL
      .from(e, scrollFadeTweenOptionsIn)
      .to(e, scrollFadeTweenOptionsOut, "=+4");
  });
});

Here is a fork of your codepen example:

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

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

16 minutes ago, OrganicBlue said:

 

BTW, why you useconst sections = gsap.utils.toArray(".section-scroll-fade");when already have let scrollFade = document.querySelectorAll(".section-scroll-fade");?

Mhhh.... I just forgot to remove the scrollFade variable definition, just that ;)

 

Happy Tweening!

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