Created
April 8, 2014 20:11
-
-
Save netsuite/10183874 to your computer and use it in GitHub Desktop.
js: preload images
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
function preloadImages(srcs) { | |
if (!preloadImages.cache) { | |
preloadImages.cache = []; | |
} | |
var img; | |
for (var i = 0; i < srcs.length; i++) { | |
img = new Image(); | |
img.src = srcs[i]; | |
preloadImages.cache.push(img); | |
} | |
} | |
// then to call it, you would use this | |
var imageSrcs = []; | |
setTimeout(function() { | |
imageSrcs.push("/siteImg/lb-mugs-large.jpg"); | |
preloadImages(imageSrcs); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment