Skip to content

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

License

Notifications You must be signed in to change notification settings

noeldelgado/image-halt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 if not loaded yet
images.forEach(function(image) {
  if (!image.isLoaded()) {
    image.abort();
  }
});

Basic Methods

name description return
load Creates a new in-memory image object and start listening for it to load. self
abort Cancel the image transfer. self

Other Methods

name description return
isLoaded Returns whether or not the image has already been loaded. Boolean

License

MIT © Noel Delgado

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published