Created
June 6, 2014 15:06
-
-
Save m1erickson/1dbeeae071e986ddc45c to your computer and use it in GitHub Desktop.
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
// image loader | |
var imageURLs=[]; // put the paths to your images here | |
var imagesOK=0; | |
var imgs=[]; | |
imageURLs.push(""); | |
loadAllImages(start); | |
function loadAllImages(callback){ | |
for (var i=0; i<imageURLs.length; i++) { | |
var img = new Image(); | |
imgs.push(img); | |
img.onload = function(){ | |
imagesOK++; | |
if (imagesOK>=imageURLs.length ) { | |
callback(); | |
} | |
}; | |
img.onerror=function(){alert("image load failed");} | |
img.crossOrigin="anonymous"; | |
img.src = imageURLs[i]; | |
} | |
} | |
function start(){ | |
// the imgs[] array now holds fully loaded images | |
// the imgs[] are in the same order as imageURLs[] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment