There is always a minor problem when it comes to preloading image on a website. Nobody really has a full solution for it. There are a lot of preloaders available, but most of the time they only display the words: “Loading page” or have an animated image that spins. Why can’t there be a nice loading bar of some kind?
I’ve gotten a few request on how to make a preloader, or people asking me how to get all the images of a web page and preload them (even the images in CSS).
This preloader has it all. Loading bar, custom animations and getting all images included in the web page.
(a special shout out goes to Sieb of Siebdesign for coming up with the animation and the idea of building a preloader)
Download the source code here:
View the example here:
Example with percentage visible:
http://www.gayadesign.com/scripts/queryLoaderPercentage/ or download: http://www.gayadesign.com/scripts/queryLoader2/qL2.zip (thanks to Olivier Dumetz)
- Preload a whole web page.
- Preload a part of the page.
- Gets all images, <img> tags and background-image of your CSS
- Easy to implement.
- Adjustable loading bar.
- Tested in Firefox, Safari, Opera, Chrome, IE7, IE8 and IE6 (script will be ignored in IE6 though).
1. Download the zipped archive.
2. Upload the contents to your webserver.
3. Place the following code in thepart of your page:
Remove the jQuery part if you have already included the file.
4. Place this code at the bottom of your page:
You are now done!
If you only want one element / container to be preloaded you can setup a jQuery selector to only preload what you want.
Let's say you have an element with an id. You only want the images inside that element to be preloaded. You can use the following code:
Be aware that you can only preload a single element. So using a class selector could cause some problems.
To read more about selectors in jQuery you can read this page in the jQuery docs.
To adjust the animations of the loading bar, you can take a look in the following functions:
QueryLoader.animateLoader() and QueryLoader.doneLoad()
Adjusting these functions requires a bit of jQuery knowledge.
Any questions about QueryLoader and implementations can be posted in the comments below.
Good luck and happy developing.