1.1.0 • Published 8 years ago

image-preloader-promise v1.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

image-preloader-promise

Preload an image or a collection of images and return a promise (ES6)

installation

node:

npm install image-preloader-promise

usage

preload a single image

ImagePreloader.preloadImage(imageSrc)
	.then(() => {
		console.log('Image loaded!');		
	})
	.catch((error) => {
		console.log('The image was not able to be loaded!');
	});

preload multiple images

let imagePath = ['https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', 'http://somesite/someimage.gif'];
ImagePreloader.preloadImages(imagePath)
	.then(function (data) {
		console.log('At least one image was loaded!');
		for (var x = 0; x < data.length; x++) {
			console.log(`image ${x} was ${data[x].state}`);
		}
	})
	.catch(function (err) {
		console.log('None of the images were able to be loaded!');
	});