An open API service indexing awesome lists of open source software.

https://github.com/pspgbhu/preloadimg

🌅 A library for preload images
https://github.com/pspgbhu/preloadimg

preload preload-image preload-images preloadimg

Last synced: 11 months ago
JSON representation

🌅 A library for preload images

Awesome Lists containing this project

README

          

# preloadimg

[![npm package](https://img.shields.io/npm/v/preloadimg.svg?style=flat-square)](https://www.npmjs.org/package/preloadimg)
[![NPM downloads](http://img.shields.io/npm/dm/preloadimg.svg?style=flat-square)](https://npmjs.org/package/preloadimg)

A library for preload images

---

## Install
`npm install --save preloadimg`

## Usage
Use in script tag
```html

var imgs = [
'img/image1.png',
'img/image2.png',
'img/image3.png',
];

preloadimg(imgs, success => { // everyone image preloaded success
console.log(success);

}, fail => { // everyone image preloaded fail
console.log(fail)

}, () => {   // it will be called when all images preloaded whatever succeeded or failed
console.log('all images preload completely!')
});

```
Use in ES6 modules or CommonJS
```js
// in ES6 modules
import preloadimg from 'preloadimg';

// in CommonJS
// var preloadimg = require('preloadimg');

preloadimg([
'img/image1.png',
'img/image2.png',
'img/image3.png',
], success => { // everyone image preloaded success
console.log(success);
}, fail => { // everyone image preloaded fail
console.log(fail)
}, () => {   // it will be called when all images preloaded whatever succeeded or failed
console.log('all images preload completely!')
});
```