https://github.com/ayamflow/images-ready
Wait for a set of images to be loaded.
https://github.com/ayamflow/images-ready
Last synced: 4 months ago
JSON representation
Wait for a set of images to be loaded.
- Host: GitHub
- URL: https://github.com/ayamflow/images-ready
- Owner: ayamflow
- Created: 2015-03-21T21:33:03.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-21T21:33:31.000Z (over 11 years ago)
- Last Synced: 2025-04-12T19:09:23.180Z (about 1 year ago)
- Language: JavaScript
- Size: 457 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
images-ready
===
Wait for a set of images to be loaded.
## Installation
`npm i images-ready --save`
## Usage
`onImagesReady(images, callback)`
* `images` can be an array or a NodeList of HTMLImageElements.
* `callback` must be a function, called when all the images are loaded.
The callback is passed an `images` array that contains a list of object containing the image and its load event, in the same order the images were passed to the function.
`images`
* `img` the origin HTMLImageElement object
* `event` the load event
## Example
```js
var onImagesReady = require('images-ready');
var $images = document.querySelectorAll('img');
onImagesReady($images, function(images) {
for(var i = 0; i < images.length; i++) {
context.drawImage(images[i].img, 0, 0);
}
});
```