Add script to your document:
<script type="text/javascript" src="browser-image-preloader/index.js"></script>
Preload images:
browserImagePreloader('path/to/image1.png', 'path/to/image2.png', 'path/to/image3.png').load();
Add handlers:
browserImagePreloader('path/to/image1.png', 'path/to/image2.png', 'path/to/image3.png')
.loaded( function (img, percent) {
console.log(img.src, 'loaded at', percent);
})
.done( function () {
console.log('finished loading images');
}).load();
We can treat browser-image-preloader
as a CommonJS module if using something like Browserify:
var preloader = require('browser-image-preloader');