image-preload
v1.0.6
Published
Simple, framework-agnostic image preloader. Async, sync, background, foreground, whatever!
Downloads
344
Maintainers
Readme
image-preload
Simple, framework-agnostic image preloader. Async, sync, background, foreground, whatever!
Installation
npm install --save image-preload
Or you can use a browser script available from https://unpkg.com/[email protected]/browser/main.js
.
Minimal usage
import Preload from "image-preload";
Preload(["https://i.imgur.com/VCr4saa.png"]);
Async, in background usage
import Preload from "image-preload";
Preload(["https://i.imgur.com/VCr4saa.png"], {
inBackground: true,
toBase64: true,
onSingleImageComplete: base64 => console.log(base64)
});
Sorting options usage
import Preload, { Order } from "image-preload";
Preload(["https://i.imgur.com/VCr4saa.png"], { order: Order.AllAtOnce });
// or
Preload(["https://i.imgur.com/VCr4saa.png"], { order: Order.InOrder });
All options
type Options = {
order?: Order;
timeout?: number;
shouldContinueOnFail?: boolean;
toBase64?: boolean;
inBackground?: boolean;
onSingleImageFail?: Function;
onSingleImageComplete?: Function;
onComplete?: Function;
};
Defaul options
const defaultOptions = {
order: Order.InOrder,
timeout: 0,
shouldContinueOnFail: true,
toBase64: false,
inBackground: false,
onSingleImageFail: () => {},
onSingleImageComplete: () => {},
onComplete: () => {}
};