Created
May 26, 2013 22:41
-
-
Save Dare-NZ/5654293 to your computer and use it in GitHub Desktop.
jQuery image preloader function, pass an url/id and it will run the callback once the image has loaded. Natch.
This file contains hidden or 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
preload_image : function(image, callback) { | |
$preload_images = $('#preload-images'); | |
if($preload_images.size() < 1) | |
$preload_images = $('<div id="preload-images" style="display:none" />').prependTo('body'); | |
$preload_images.append('<img data-id="' + image.id + '"src="' + image.src + '" />'); | |
$preload_images.find(' img[data-id=' + image.id + ']').load(function(e){ | |
if(typeof(callback) == 'function') callback(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment