Last active
August 29, 2015 14:07
-
-
Save schmidtsonian/c9be4ef54e078ee66c17 to your computer and use it in GitHub Desktop.
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
loader = { | |
// arreglo con ruta de las imágenes | |
images: [], | |
// Se ejecuta al cargar las imágenes | |
onComplete: function(){}, | |
init: function(){ | |
var self = this, count = 0; | |
var onLoadImage = function(src){ | |
console.log( 'load', count, src ); | |
count++; | |
console.log(count, 'de', self.images.length) | |
if (count >= self.images.length) { | |
self.onComplete(); | |
}; | |
} | |
self.images.forEach(function(src) { | |
console.log(src); | |
var img = new Image(); | |
img.src = src; | |
img.onload = function(){ onLoadImage(src) }; | |
}); | |
}, | |
} | |
/* | |
* Usage | |
*/ | |
loader.images = [ | |
'http://peach.blender.org/wp-content/uploads/poster_bunny_big.jpg', | |
'http://4.bp.blogspot.com/-gCfZrJ2WNCY/UDrTOp4ROcI/AAAAAAAABcQ/z93LCivcB-4/s1600/BigRock-4.jpg', | |
'http://apod.nasa.gov/apod/image/9712/orionfull_jcc_big.jpg' | |
] | |
loader.onComplete = function(){ | |
console.log('done!') | |
} | |
loader.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment