Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
_Peter_

Images Preload

Recommended Posts

Hi,

 

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

 

Thank you

 

bye

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Ok, thank you very much, it works.

 

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

 

:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Do you mean a loading gif?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 weeks later...

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

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