Skip to content

Instantly share code, notes, and snippets.

@qawemlilo
Created January 27, 2011 14:26
Show Gist options
  • Save qawemlilo/798564 to your computer and use it in GitHub Desktop.
Save qawemlilo/798564 to your computer and use it in GitHub Desktop.
Image preloading object(Class)
/*
****************************************************
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