Created
January 27, 2011 14:26
-
-
Save qawemlilo/798564 to your computer and use it in GitHub Desktop.
Image preloading object(Class)
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
/* | |
**************************************************** | |
COPYRIGHT © 2011 Raging Flame | |
AUTHOR: Qawelesizwe Mlilo | |
**************************************************** | |
*/ | |
var imgPreload = { | |
myImages: [], | |
imageFolder:[], | |
totalTime: null, | |
isComplete: false, | |
onComplete: function() { | |
console.log("All Images loaded. Time taken : " + this.totalTime +" milliseconds"); | |
}, | |
startLoading: function () { | |
var counter = 0, i, startTime = new Date().getTime(), totalImgs = imgPreload.myImages.length; | |
for (i = 0; i < totalImgs; i += 1) { | |
this.imageFolder[i] = new Image(); | |
this.imageFolder[i].onload = function() { | |
counter += 1; | |
if (counter === totalImgs && !imgPreload.isComplete) { | |
imgPreload.isComplete = true; | |
imgPreload.totalTime = (new Date().getTime() - startTime); | |
imgPreload.onComplete(); | |
} | |
}; | |
this.imageFolder[i].src = this.myImages[i]; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment