chckImgs
is a lightweight (< 400 bytes gzipped) JavaScript function to check if one or multiple images are loaded.
NPM
npm install --save chck-imgs
Bower
bower install --save chck-imgs
/**
* `chckImgs` will always resolve with an array, even if one or multiple images failed to load.
* You can loop through this array and check the `status` (`ok` or `error`) for each image
*
* @param {...String} paths
* @return {Promise.<{{path: String, status: String}}>}
*/
chckImgs('img.jpg', 'img2.jpg').then(function(imgs) {
// All images are either loaded or failed to load.
});
All major browsers are supported (IE9+). You'll have to polyfill ES6 Promises
for browsers that do not support native Promises yet.
To compile and compress chckImgs.js
, we rely on npm as a Build Tool.
-
Check out the repository
git clone [email protected]:mrksbnch/chck-imgs.git cd chck-imgs
-
Run
npm install
to install all dependencies
NPM command | Description |
---|---|
npm run lint |
(es)lint JavaScript |
npm run uglify |
Compress JavaScript |
npm run babel |
Compile ES6 to ES5 with Babel |
npm run build |
Lint, compress and minify JavaScript |
npm run watch |
Watch file changes |
Copyright 2016 Markus Bianchi. See LICENSE for details.