0.0.1 • Published 9 years ago

image-halt v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

image-halt

Preload images with an option to cancel the transfer if needed without stoping the window loading.

Read the Specification

Installation

NPM

npm i image-halt --save

Usage

var ImageHalt = require('image-halt');

var paths = ['a.jpg', 'b.png', 'c.gif'];
var images = [];

function handleImageLoad(err, image) {
	if (err) { // handle the error
		return;
	}
	
	document.body.appendChild(image);
}

// register 
paths.forEach(function(path) {
	images.push( new ImageHalt(path, handleImageLoad).load() );
});

// ...
// later on we cancel them
images.forEach(function(image) {
	if (image.isLoaded() === false) {
		image.abort();
	}
});

Basic Methods

namedescriptionreturn
loadCreates a new in-memory image object and start listening for it to load.self
abortCancel the image transfer.self

Other Methods

namedescriptionreturn
isLoadedReturns whether or not the image has already been loaded.Boolean

License

MIT © Noel Delgado