Simple javascript class for preloading images.
var preloader = new ImagePreloader({
urls: ['array', 'of', 'image', 'urls'], // URLs can be relative or absolute
imageLoad: function(imageDetails) { ... },
complete: function(imageUrls) { ... }
});
preloader.start();The optional callbacks are:
Fired when an image finishes loading. Provides an imageDetails hash containing:
{
url: 'url-of-image',
loadedCount: 2, // how many images have been loaded so far
totalCount: 4, // total image count
abort: false, // true if image load was aborted
error: false // true if image load encountered error
}Fired when all images have finished loading. Provides an array of the image URLs.
http://6.github.io/image_preloader.js/samples/example.html
Loosely based off image preloader gist by eikes: https://gist.github.com/eikes/3925183