Here is a quick hack for modern browsers:
var imgs = document.images, len = imgs.length, counter = 0; [].forEach.call( imgs, function( img ) { img.addEventListener( 'load', incrementCounter, false ); } ); function incrementCounter() { counter++; if ( counter === len ) { console.log( 'All images loaded!' ); } }
Once all the images have been uploaded, your console will display "All images uploaded!".
What this code does:
- Load all images into a variable from a document
- Scrolling through these images.
- Add a listener for the "load" event on each of these images to trigger the
incrementCounter
function incrementCounter
will incrementCounter
counter- If the counter has reached the length of the images, this means that they are all loaded.
Having this code in a cross browser won't be as complicated, it's just cleaner than that.
source share