Skip to content

Instantly share code, notes, and snippets.

@nobuti
Created September 20, 2012 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nobuti/3756881 to your computer and use it in GitHub Desktop.
Save nobuti/3756881 to your computer and use it in GitHub Desktop.
Easy jquery/zepto images preload
var images = ["path/to/image", "path/to/image", ... , "path/to/image"],
preloaded = images.length;
_.each(images, function(img) {
var image = $('<img />').attr('src', img);
image.on('load', function(){
preloaded--;
if (preloaded === 0){
console.log("All preloaded!");
}
});
});
@gabriel-r
Copy link

You'll want …
$.each(images, function(index,img) {

The index is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment