imachi
🌖
Tiny image loader.
Installation:
yarn add -D imachi
npm install -D imachi
pnpm i -D imachi
Import:
import { imachi } from "imachi";
Usage:
const loader = imachi('img');
loader.progress((event) => {
console.log(`Loading progress: ${event.progress.percentage}%`);
});
loader.done((event) => {
console.log(`All images loaded: ${event.total} images`);
});
loader.fail((event) => {
console.error(`Failed to load image: ${event.src}`);
});
Events
.progress
Called each time an image loads successfully.
const loader = imachi('img');
loader.progress((event) => {
console.log(`Loading progress: ${event.progress.percentage}%`);
});
imageElement
: HTMLImageElement
- Loaded imageprogress
count
: number
- Current countpercentage
: number
- Load completion (%)total
: number
- Total count
.done
Called when the entire loader process finishes.
const loader = imachi('img');
loader.done((event) => {
console.log(`All images loaded: ${event.total} images`);
});
images
: []
- Loaded images
src
: string
- Image sourceelement
: HTMLImageElement
- Image element
total
: number
- Total count
.fail
Called when an image fails to load.
const loader = imachi('img');
loader.fail((event) => {
console.error(`Failed to load image: ${event.src}`);
});
src
: string
- Image sourceelement
: HTMLImageElement
- Image elementerror
: Error
- Error object