Jump to content
Search Community

How to combine windows load to gsap setup reveal

Bayu Handono
Moderator Tag

Recommended Posts

Posted

How to insert/combine window load(loading until all page loaded) to function "setup reveal" in gsap. So, the page load all resource before star animation. Like this:

 

window.addEventListener("load", () => {

  const tl = gsap.timeline();

  tl.to(".loader", {

    delay: 2,

    opacity: 0,

    duration: 1,

    ease: Power3.easeOut

  });

 

function setupReveal(container) {

  container.ctx = gsap.context(() => {

 

//gsap code...

 

});

}

 

Like this but combine windowload with function setup reveal, ctx context :

See the Pen oNmjaWb by byhndo (@byhndo) on CodePen.

Posted

Hi,

 

If you want to use GSAP context maybe you can create a global GSAP Context instance outside the load event, like this:

let ctx;

window.addEventListener("load", () => {
  ctx && ctx.revert();
  ctx = gsap.context(() => {});
});

But that wouldn't make a lot of sense since the load event will trigger only once in the life cycle of the page/app.

 

The setup you have right now is the goto approach and a very solid one, so I'd keep using that.

 

Let us know if you have more questions.

Happy Tweening!

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