Jump to content
Search Community

Images Preload

_Peter_
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Posted

Hi,

 

does anyone know how to preload the images before starting with the Timeline animation?

 

Thank you

 

bye

Posted
I'm not sure which images you're referring to, but if you want to make sure everything is ready to animate you can just use these ways:
 
 
$( document ).ready(function() {
// your tweens here
});
$( window ).load(function() { 

//your tweens
});

The first way will run once the DOM is ready for Javascript. The second way runs once the entire page (i.e images) is ready.

 

More info about when the DOM is ready vs when all images are loaded etc... can be found here:

 

https://learn.jquery.com/using-jquery-core/document-ready/

 

I hope this helps. :)

 

 

 

  • Like 3
Posted

Ok, thank you very much, it works.

 

And how do I show an image or a text until the window is loaded?

Posted

That woudl be the 2nd one PointC suggested window load

 

But you could do a mix of the 2 ways PointC suggested which is what i usually do:

// wait until DOM is ready
$( document ).ready(function() {
   
    // wait until images, links, style-sheets, and other assets are loaded
    $( window ).load(function() { 

       // your tweens

    });

});

:)

  • Like 2
Posted

Yep - Jonathan's mix of those two is usually the best way to go. :)

 

In reading your follow up question though - are you asking about showing separate text or an image while the page is loading?

 

If that is the case, you really wouldn't need any sort of loading animation or message unless your page takes a really long time to load and you need to let the visitor know that things are happening. For most cases though, the page will load quickly and the animations can start.

 

Those scripts we listed above simply make sure all the elements of the page are loaded and ready to animate before the tweens start so you don't get any errors. 

 

:)

Posted

I mean: an image that is showing while the page is loading. In my case, my page takes a long time because the photos are very large.

Posted

Yes, an ajax approach, or something like that, would be better but it's ok anyway.

Posted

I have only the basis of ajax but im trying to learn how to make a progressive bar or percent... but i dont know if it's the right approach with greensock.

Posted

This could have been done in many ways. I just have a class with a background-image using a gif. And the when the DOM is ready and window is loaded. I remove the class with the background image.

 

Keep in mind i use a delayedCall() which is the same as setTimeout() to simulate the page loading, but you would not use that in a production environment

 

See the Pen jbdgPg by jonathan (@jonathan) on CodePen.

 

You could also try fading in your content after window load and the loader class is removed.

 

Regarding loaders with percent. Here is calculating percentage:

 

See the Pen keEyq by jonathan (@jonathan) on CodePen.

 

The percentage is done by tapping intyo the GSAP onUpdate callback.. check the GSAP Docs here : http://greensock.com/docs/#/HTML5/

 

Here is a basic image slider with a progress bar:

 

See the Pen qxsfc by jonathan (@jonathan) on CodePen.

 

Here is just a repeating progress bar:

 

See the Pen RNKPLo by jonathan (@jonathan) on CodePen.

 

GreenSock can make any type of loader or progress bar, it just depends what you want to create!

 

GSAP can animate any JavaScript object or property so it is great at timing your animations or building a timer for your animations.

 

:)

  • Like 2
  • 3 weeks later...
Posted

Here is what I do for image preloading from an array.    

 

See the Pen JGdGPy by rfenik (@rfenik) on CodePen.

 

Edit:  

 

Here is another version that animates the timeline of an svg:  

 

See the Pen MKwjwy by rfenik (@rfenik) on CodePen.

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