Skip to content

Instantly share code, notes, and snippets.

@maxpoletaev
Created September 24, 2013 13:53
Show Gist options
  • Save maxpoletaev/6685092 to your computer and use it in GitHub Desktop.
Save maxpoletaev/6685092 to your computer and use it in GitHub Desktop.
/**
* Preloading images.
* @public
*
* @param {Object} images
* @param {Function} callback
*/
function preloadImages(images, callback) {
var callback = callback || null;
var notLoaded = images.length;
$.each(images, function(i, image) {
$(new Image()).attr('src', image)
.load(function() {
if (--notLoaded < 1 && callback) callback();
});
;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment