Skip to main content

Callbacks

note

All Module callbacks are available in this class.

loaded​

Triggered once, when the page is fully loaded.

const preloader = new Preloader({
container: document.getElementById('container'),
onLoaded: () => console.log('loaded'),
});

or:

const destruct = preloader.on('loaded', () => console.log('loaded'));

// Cancel the callback
destruct();

requestHide​

Triggered when the page is loaded and a hide is requested.
Fires immediately after loaded, before hide starts. When hide is a number, auto-hide follows in the same tick.

Use this callback for custom hide timing with hide: false — e.g. call hide() once your own readiness checks pass.

const preloader = new Preloader({
container: document.getElementById('container'),
hide: false,
onRequestHide: () => preloader.hide(500),
});

or:

const destruct = preloader.on('requestHide', () => console.log('requestHide'));

// Cancel the callback
destruct();

hide​

Triggered when the preloader starts hiding — either automatically (if hide props is a number) or via manual .hide().
Preceded by requestHide.

const preloader = new Preloader({
container: document.getElementById('container'),
onHide: () => console.log('hide'),
});

or:

const destruct = preloader.on('hide', () => console.log('hide'));

// Cancel the callback
destruct();

hidden​

Triggered only after the hiding animation fully completes.
If hiding is disabled (hide: false) — this callback runs only after a manual .hide().

const preloader = new Preloader({
container: document.getElementById('container'),
onHidden: () => console.log('hidden'),
});

or:

const destruct = preloader.on('hidden', () => console.log('hidden'));

// Cancel the callback
destruct();