Created
November 11, 2014 12:34
-
-
Save hitautodestruct/317984e09d11bf34dee2 to your computer and use it in GitHub Desktop.
A javascript image preloader. Accepts an array of image paths and then initiates a callback when done loading.
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
// Accepts array of image paths relative to the current page. | |
var preLoadImages = function( srcs, callback ) { | |
if ( srcs.length ) { | |
var cache = [], | |
args_len = srcs.length; | |
for (var i = args_len; i--;) { | |
var cacheImage = document.createElement('img'); | |
cacheImage.src = srcs[i]; | |
cacheImage.onload = callback; | |
cache.push(cacheImage); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment