Created
November 27, 2012 14:33
-
-
Save alloyking/4154524 to your computer and use it in GitHub Desktop.
Preload Images
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
this.addEventListener("DOMContentLoaded", preloadImages, true); | |
var loadedImages = 0; | |
var imageArray = new Array("path-to-image", "path-to-image"); | |
function preloadImages(e) | |
{ | |
for (var i=0; i<imageArray.length; i++) { | |
var tempImage = new Image(); | |
tempImage.addEventListener("load", trackProgress, true); | |
tempImage.src = imageArray[i]; | |
} | |
} | |
function trackProgress() { | |
loadedImages++; | |
if (loadedImages == imageArray.length) { | |
imagesLoaded(); | |
} | |
} | |
function imagesLoaded() { | |
// do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment