Every demo below runs the real library — the same ~2 kB gzipped bundle that ships from npm. Two functions, zero dependencies, full control.
A splash over the whole page covers the viewport — nothing beneath it
moves, and neither does your scroll position.
show() returns a monotonic nsId you can hand
back to hide(id). These demos hide themselves after two
seconds so you get the page back.
const id = ns.show('Brewing coffee') // → nsId ns.hide(id) // or ns.hide() for oldest, ns.hide('*') for all
Pass an element, a CSS selector, or a ref as the second argument. A container that already holds a splash recycles it — reload a widget twice and the label updates instead of stacking a duplicate.
ns.show('Crunching numbers', '#w-revenue') ns.show('Almost there', '#w-revenue') // recycled — text updates, no duplicate
Hand show() a [label, job] pair and it runs
the work under the splash, auto-hiding when it settles. An array of
pairs runs sequentially under one splash — the label
updates per step, and results come back as a typed tuple. Sequences
are fail-fast; rejections propagate after the splash hides.
const [user, posts, ok] = await ns.show([ ['Loading user', () => fetchUser()], ['Loading posts', () => fetchPosts()], ['Verifying', () => verify()], ], '#stage-jobs') // typed tuple, in order
Two sins of loading screens: the flash of spinner on a fast operation,
and the sub-100 ms blink. showDelay keeps the splash
invisible for operations that finish quickly;
minDuration holds it long enough to register. Run the
same task through both instances and watch the right one behave.
const ns = useNs({ showDelay: 250, minDuration: 600 }) // <250 ms task → splash never becomes visible // visible splash → held ≥600 ms, no blink
Every visual knob is a public CSS custom property with defaults
declared on :where(:root) — zero specificity, so your
overrides always win. Adjust these while the splash is showing;
changes apply live.
/* your stylesheet */ :root { --ns-bg: #0b151bcc; --ns-color: #3bc6ef; --ns-blur: blur(8px); }
The splash is a proper live region — no configuration required. Press the button and the chips below light up as each attribute is verified on the live DOM element, not hard-coded.
The spinner animation also respects
prefers-reduced-motion — with it enabled, the dash
animation is replaced by a slow, steady rotation.