Skip to content
Simple javascript image preloader
CoffeeScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
samples
README.md
bower.json
component.json
image_preloader.coffee
image_preloader.js

README.md

Simple javascript class for preloading images.

Usage

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:

imageLoad

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
}

complete

Fired when all images have finished loading. Provides an array of the image URLs.

Example

http://6.github.io/image_preloader.js/samples/example.html

Credits

Loosely based off image preloader gist by eikes: https://gist.github.com/eikes/3925183

Something went wrong with that request. Please try again.