Skip to content

Instantly share code, notes, and snippets.

@tombeynon
Created December 7, 2012 09:34
Show Gist options
  • Save tombeynon/4232133 to your computer and use it in GitHub Desktop.
Save tombeynon/4232133 to your computer and use it in GitHub Desktop.
jQuery preload images with callback
// Pass an array of image locations, and an optional callback function
function preload_images(images, callback){
var preloaded = 0;
jQuery.each(images, function(index, image){
var image = $('<img />').attr('src', image).load(function(){
preloaded++;
if(preloaded == images.length){ callback(); }
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment