Skip to content

Instantly share code, notes, and snippets.

@smcan
Forked from nobuti/gist:3756881
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smcan/86d981bd2a987586c986 to your computer and use it in GitHub Desktop.
Save smcan/86d981bd2a987586c986 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!");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment