1.2.0 • Published 2 years ago

bianco.images-loader v1.2.0

Weekly downloads
146
License
MIT
Repository
github
Last release
2 years ago

bianco.images-loader

Build Status NPM version NPM downloads MIT License

Modern images loader helpers written in es2015 using promises

Usage

Load a single image

import { loadImage } from 'bianco.images-loader'

loadImage('path/to/the/image.jpg').then(img => document.body.appendChild(img))

Or also DOM nodes:

import $ from 'bianco.query'
import { loadImage } from 'bianco.images-loader'

loadImage($('img.cool'))
  .then(img => img.classList.add('loaded'))
  .catch(function(error) {
    // there was an error loading the image
  })

Load a multiple images

import { loadImages } from 'bianco.images-loader'

loadImages([
    'path/to/the/image1.jpg',
    'path/to/the/image2.jpg'
  ])
  .then(imgs => imgs.forEach(i => document.body.appendChild(i)))
  .catch(error => {
    // there was an error loading one of images
  })

Or also...

import $ from 'bianco.query'
import { loadImages } from 'bianco.images-loader'

loadImages($('img', '.main-content'))
  .then(imgs => imgs.forEach(i => i.classList.add('loaded')))
  .catch(error => {
    // there was an error loading one of images
  })

API

Table of Contents

loadImage

Preload any image

Parameters

Returns Promise a promise that will be resolved when the image will be completely loaded

loadImages

Load in parallel a collection of images

Parameters

Returns Promise a promise that will be resolved when all the images will be loaded

1.2.0

2 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.0

5 years ago

0.0.7

6 years ago

0.0.5

7 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago