Created
December 7, 2012 09:34
-
-
Save tombeynon/4232133 to your computer and use it in GitHub Desktop.
jQuery preload images with callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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