Jump to content
Search Community

Images Preload

_Peter_ test
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

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

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

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

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