Created
June 1, 2016 10:44
-
-
Save oreillyross/d6b9c0767837cf653a8f80f4a521d5a4 to your computer and use it in GitHub Desktop.
A MULTIPLE IMAGE LOADER THAT COUNTS THE LOADED IMAGES AND CALLS A FUNCTION YOU PASS WHEN DONE!
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 loadImages(imagesToBeLoaded, drawCallback) { | |
var imagesLoaded = {}; | |
var loadedImages = 0; | |
var numberOfImagesToLoad = 0; | |
// get num of images to load | |
for(var name in imagesToBeLoaded) { | |
numberOfImagesToLoad++; | |
} | |
for(var name in imagesToBeLoaded) { | |
imagesLoaded[name] = new Image(); | |
imagesLoaded[name].onload = function() { | |
if(++loadedImages >= numberOfImagesToLoad) { | |
drawCallback(imagesLoaded); | |
} // if | |
}; // function | |
imagesLoaded[name].src = imagesToBeLoaded[name]; | |
} // for | |
} // function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment