Jump to content
Search Community

Images flash in initial load

AdMan123 test
Moderator Tag

Recommended Posts

Hi,

 

I've been looking at your codepen for a few minutes and I find it extremely convoluted and difficult to follow. This part for example:

function darkenExcept(id) {
  for (let i = 1; i <= 6; i++) {
    const selector = `#content-image-${i}`;
    if (selector === id) {
      gsap.to(selector, {
        opacity: 1,
        css: { filter: "brightness(100%)" },
        duration: 0.5
      });
    } else {
      gsap.to(selector, {
        opacity: 0.5,
        css: { filter: "brightness(50%)" },
        duration: 0.5
      });
    }
  }
}

// Add the animations to the timeline
for (let i = 1; i <= 6; i++) {
  tl1.add(() => darkenExcept(`#content-image-${i}`));
  tl1.to({}, { duration: 1 }); // Add a pause of 2 seconds
}

Could be done with just one loop and in a far simpler way and I believe this is the issue you have in your code. Keep in mind that the add method is adding a call to a function to the timeline, not the GSAP instance created in the darkenExcept function.

 

Based on the sequence you have right now I forked your codepen and removed everything except for the images:

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

 

Hopefully this helps.

Happy Tweening!

  • Like 1
  • Thanks 1
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...