Walter.js is a Javascript library that does all common things that you usually do when preload images. In this way Walter.js exports an easy Api based on Promises and events in wich you can subscribe for know the status of each image.
var promise = Walter('picture.jpg');
var promise = Walter(['picture1.jpg', 'picture2.jpg']);
var promise = Walter(['picture1.jpg', 'picture2.jpg']);
//It's called when each image is loaded
promise.progress(function(index, img) {
console.log(index, img);
});
//It's called when all images are loaded
promise.then(function(images) {
console.log('then', images);
});
//It's called if some image has error
promise.catch(function(promise) {
console.log('catch', promise);
});
You can also use Walter.js with chain style
promise.then(onComplete).catch(onError).progress(onUpdate);
Walter.config({
path: 'assets/images'
});
None :D
- npm install
- grunt test
- Add RSVP library for support old browsers
- Document code