🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

z-image-preloader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z-image-preloader

A Promise-based image preloader solution.

latest
Source
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

z-image-preloader

npm version

Creates a promise object which is resolved when all images are loaded.

Note: The module depends on the global Promise object to be available.

Since it's a CommonJS module, you must use a build tool to use it, like Browserify, or webpack.

Example, explanation

const preloader = require("z-image-preloader");

// load single image
preloader
    .load("http://some-url/some-image.png")
    .then(img => {
        // done loading
    })
    .catch(e => {
        // failed to load
    });

// The `batchLoad` method accepts an array of url strings. (Or a single url.)
// The returned promise will be resolved, when all images are loaded (or failed to load)
preloader
    .batchLoad([
        "http://some-url/some-image.png",
        "http://some-other-url/some-other-image.jpg",
        "non-existent-image"
    ])
    .then((img1, img2, err) => {
        // Do something when preloading is done.
        // The arguments here will contain the loaded image objects created by `document.createElement('img')` and possible Error objects.
        // The above call for example will return with two `HTMLImageElement` and an `Error`.
    });

LICENSE

MIT

Keywords

promise

FAQs

Package last updated on 08 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts