Jump to content
Search Community

Immediate execution of tween on page reload

blende64 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello

I have a page with a fixed header. The header should be transparent when the page is initially loaded. When the user scrolls about 100 pixels, the header should get a background color. I was able to implement this in the attached CodePen. However, I have noticed the following problem: If the user scrolls to section 3, for example, and then reloads the page, the header is displayed transparently for a brief moment until the tween has been executed. How can I ensure that the header is immediately provided with the background color when the page is reloaded?

Thank you very much

See the Pen abMEVLJ by blatthirsch (@blatthirsch) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

I'm not sure I follow 100% what you're trying to do, but maybe something like this?

 

t = gsap.to("#header_bg", {
  autoAlpha: 1,
  scrollTrigger: {
    trigger: "#content",
    start: "+=100px",
    toggleActions: "play none none reverse",
  }
});

if (window.scrollY >= 100) {
  t.progress(1);
}

Hopefully this helps.

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