Jump to content
Search Community

Page preloader where there will be a progress bar and percentage while the js and images are still loading..

Louienator test
Moderator Tag

Recommended Posts

Hi is that possible in gsap to have a preloader, then animate everything after the preloader/js assets are done loading? And that preloader will just be shown on the first page only, and if cached, it will not show?

 

I have no working pen on that, just a thought if it's possible?

 

Thank you so much.

Link to comment
Share on other sites

Hi,

 

Sure thing, just make sure that your preloader has some callback so once everything is loaded you can execute your code with your animations. As for caching I'm not completely sure about checking that particular situation. I know that HTTP has cache control but nothing beyond that, so you'll have to do some research in order to achieve that particular part.

 

Here is an example (old) that uses a spinner and a canvas preloader to load some images:

See the Pen AWXJvK by rhernando (@rhernando) on CodePen

 

Is not exactly what you're looking for, but hopefully is enough to get you started.

Happy Tweening!

Link to comment
Share on other sites

From a setup perspective @Rodrigo's already shared an example that does this. There are many different ways you could approach it though. A lot of progress bars aren't even linked up to the page load or asset loading, they're just aesthetic. (not that I recommend that 🫠)

Did you take a look at it, is there something you don't understand?


The aesthetic side (progress bar and showing contents) really just depends on what the animation looks like. There's no one solution or out of the box plugin here.

 

There are onComplete callbacks you could make use of. They run at the end of a tween or timeline. Here's some pseudocode - a simple tween that's showing some hidden content when onComplete gets called:

onComplete: () => { 
  gsap.to(".hiddenContent", {autoAlpha: 1})
}

 

Maybe the getting started guide would be helpful?


 

  • Like 1
Link to comment
Share on other sites

13 hours ago, Louienator said:

And oh, how does the percentage be achieved, while waiting for the js to load? and the percentage will depend on the net connection or the js loaded.. thanks..

We really try to keep these forums focused on GSAP-specific questions, sorry. 

 

To get the percentage, you'd need to figure out all the things that are loading, their sizes, and then do the math as things load. Again, none of this has anything to do with GSAP which is just a high-speed property manipulator. :) 

Link to comment
Share on other sites

On 4/23/2023 at 11:20 PM, Cassie said:

A lot of progress bars aren't even linked up to the page load or asset loading, they're just aesthetic. (not that I recommend that 🫠)

Hey @Cassie! Hope you're really well.

Just curious - found this thread after searching high and low for the right mix of imagesloaded.js/preload.js style preloading library to hook up with a GSAP progress animation...

Pretty much all the walkthroughs/examples I can find don't link up to real asset/page load, as you mentioned... they just use a callback on preload complete, firing a timeline with an arbitrary length. 

 

Maze of options to tie the animation to real progress, which is my preference!

So my question - why would you recommend linking it to real page load time? My instinct is that's a bit more honest and UX friendly... but also keen not to have a progress bar fade out too early, say if it's not reached 100%.

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