Curtain page loader
A first-visit loader: big numerals count to 100 at a realistic, uneven pace, then a dark and an orange curtain lift to show the page.
"use client";
import { useEffect, useRef, useState, type ReactNode } from "react";
import "./curtain-loader.css";
type CurtainLoaderProps = {
/** The page (or section) that sits behind the curtain. */
children: ReactNode;
/** How long the count takes, in milliseconds. */
duration?: number;
/** Small line above the counter. */
label?: string;
/** Called once the curtain has fully lifted. */
onDone?: () => void;
};
// Real loading never moves at an even pace: it rushes, stalls, then finishes.
// Each pair is [share of the time, share of the count].
const PACE: [number, number][] = [
[0, 0],
[0.22, 0.34],
[0.38, 0.38],
[0.62, 0.74],
[0.78, 0.8],
[1, 1],
];
function paced(t: number) {
for (let i = 1; i < PACE.length; i++) {
const [t1, v1] = PACE[i];
const [t0, v0] = PACE[i - 1];
if (t <= t1) {
const k = (t - t0) / (t1 - t0);
const smooth = k * k * (3 - 2 * k);
return v0 + (v1 - v0) * smooth;
}
}
return 1;
}
/**
* CurtainLoader
* Counts 0 to 100 in large numerals, then lifts in two layers to show the
* page underneath. Use it for a first visit, not on every page change.
*/
export function CurtainLoader({
children,
duration = 2400,
label = "Loading",
onDone,
}: CurtainLoaderProps) {
const [count, setCount] = useState(0);
const [phase, setPhase] = useState<"counting" | "lifting" | "gone">(
"counting",
);
const doneRef = useRef(onDone);
useEffect(() => {
doneRef.current = onDone;
}, [onDone]);
useEffect(() => {
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
const total = reduce ? 600 : duration;
let frame = 0;
const start = performance.now();
const tick = (now: number) => {
const t = Math.min(1, (now - start) / total);
setCount(Math.round((reduce ? t : paced(t)) * 100));
if (t < 1) frame = requestAnimationFrame(tick);
else setPhase("lifting");
};
frame = requestAnimationFrame(tick);
return () => cancelAnimationFrame(frame);
}, [duration]);
return (
<div className="gu-curtain" data-phase={phase}>
<div className="gu-curtain__page" aria-busy={phase === "counting"}>
{children}
</div>
{phase !== "gone" && (
<div
className="gu-curtain__cover"
role="progressbar"
aria-label={label}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={count}
onTransitionEnd={(e) => {
// The back layer lags behind, so it is the last thing to move.
if (e.target === e.currentTarget.firstElementChild) {
setPhase("gone");
doneRef.current?.();
}
}}
>
<div className="gu-curtain__layer gu-curtain__layer--back" />
<div className="gu-curtain__layer gu-curtain__layer--front">
<span className="gu-curtain__label">{label}</span>
<span className="gu-curtain__count" aria-hidden="true">
{count}
</span>
</div>
</div>
)}
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Curtain page loader
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A first-visit page loader. Large numerals count from 0 to 100 at an uneven, believable pace, then two curtains lift (a dark one, then an orange one a beat behind) and the page underneath settles into place.
## Behavior and motion
- The count runs on requestAnimationFrame over `duration` (default 2400ms). It follows a paced curve instead of a straight line: rush to 34% by 22% of the time, stall at 38%, climb to 74% by 62%, stall at 80%, finish. Between points use smoothstep.
- At 100 the curtains lift: both layers translateY(−101%) over 1s with cubic-bezier(0.76, 0, 0.24, 1); the orange back layer has a 0.12s delay, so it trails the dark one.
- While counting, the page sits 40px lower and glides up (1.2s) as the curtain lifts.
- When the back layer's transition ends, the cover is removed from the page and `onDone` is called.
## Look
- Front layer: ink #0e0e10 with cream text and 6% padding. A small label at the top (600 weight, cream at 70%); the count at the bottom right, weight 900, clamp(4rem, 30cqi, 14rem), line-height 0.8, tracking −0.06em, tabular numbers.
- Back layer: orange #ff5a1f.
- Demo: a cream hero ("Chairs you can fix with a screwdriver.") behind the curtain, and a "Load again" button that is enabled once loading has finished.
## Accessibility
- The cover is role="progressbar" with the label and aria-valuenow. The numerals are aria-hidden. The page has aria-busy while counting.
- Use it once per visit (for example, remember it in sessionStorage), not on every page change.
- prefers-reduced-motion: a quick 0.6s count, the curtains fade out instead of lifting, and the page does not move.
## Props
children (the page), duration (ms), label, onDone.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### CurtainLoader.tsx
```tsx
"use client";
import { useEffect, useRef, useState, type ReactNode } from "react";
import "./curtain-loader.css";
type CurtainLoaderProps = {
/** The page (or section) that sits behind the curtain. */
children: ReactNode;
/** How long the count takes, in milliseconds. */
duration?: number;
/** Small line above the counter. */
label?: string;
/** Called once the curtain has fully lifted. */
onDone?: () => void;
};
// Real loading never moves at an even pace: it rushes, stalls, then finishes.
// Each pair is [share of the time, share of the count].
const PACE: [number, number][] = [
[0, 0],
[0.22, 0.34],
[0.38, 0.38],
[0.62, 0.74],
[0.78, 0.8],
[1, 1],
];
function paced(t: number) {
for (let i = 1; i < PACE.length; i++) {
const [t1, v1] = PACE[i];
const [t0, v0] = PACE[i - 1];
if (t <= t1) {
const k = (t - t0) / (t1 - t0);
const smooth = k * k * (3 - 2 * k);
return v0 + (v1 - v0) * smooth;
}
}
return 1;
}
/**
* CurtainLoader
* Counts 0 to 100 in large numerals, then lifts in two layers to show the
* page underneath. Use it for a first visit, not on every page change.
*/
export function CurtainLoader({
children,
duration = 2400,
label = "Loading",
onDone,
}: CurtainLoaderProps) {
const [count, setCount] = useState(0);
const [phase, setPhase] = useState<"counting" | "lifting" | "gone">(
"counting",
);
const doneRef = useRef(onDone);
useEffect(() => {
doneRef.current = onDone;
}, [onDone]);
useEffect(() => {
const reduce = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
const total = reduce ? 600 : duration;
let frame = 0;
const start = performance.now();
const tick = (now: number) => {
const t = Math.min(1, (now - start) / total);
setCount(Math.round((reduce ? t : paced(t)) * 100));
if (t < 1) frame = requestAnimationFrame(tick);
else setPhase("lifting");
};
frame = requestAnimationFrame(tick);
return () => cancelAnimationFrame(frame);
}, [duration]);
return (
<div className="gu-curtain" data-phase={phase}>
<div className="gu-curtain__page" aria-busy={phase === "counting"}>
{children}
</div>
{phase !== "gone" && (
<div
className="gu-curtain__cover"
role="progressbar"
aria-label={label}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={count}
onTransitionEnd={(e) => {
// The back layer lags behind, so it is the last thing to move.
if (e.target === e.currentTarget.firstElementChild) {
setPhase("gone");
doneRef.current?.();
}
}}
>
<div className="gu-curtain__layer gu-curtain__layer--back" />
<div className="gu-curtain__layer gu-curtain__layer--front">
<span className="gu-curtain__label">{label}</span>
<span className="gu-curtain__count" aria-hidden="true">
{count}
</span>
</div>
</div>
)}
</div>
);
}
```
### curtain-loader.css
```css
.gu-curtain {
--gu-curtain-ink: #0e0e10;
--gu-curtain-paper: #f3eee3;
--gu-curtain-accent: #ff5a1f;
--gu-curtain-ease: cubic-bezier(0.76, 0, 0.24, 1);
position: relative;
overflow: hidden;
container-type: inline-size;
}
/* The page waits a touch lower and settles as the curtain lifts. */
.gu-curtain__page {
transition: transform 1.2s var(--gu-curtain-ease);
}
.gu-curtain[data-phase="counting"] .gu-curtain__page {
transform: translateY(40px);
}
.gu-curtain__cover {
position: absolute;
inset: 0;
z-index: 10;
}
.gu-curtain__layer {
position: absolute;
inset: 0;
transition: transform 1s var(--gu-curtain-ease);
}
/* An orange sheet trails the dark one by a beat. */
.gu-curtain__layer--back {
background: var(--gu-curtain-accent);
transition-delay: 0.12s;
}
.gu-curtain__layer--front {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 6%;
background: var(--gu-curtain-ink);
color: var(--gu-curtain-paper);
}
.gu-curtain[data-phase="lifting"] .gu-curtain__layer {
transform: translateY(-101%);
}
.gu-curtain__label {
font:
600 0.9rem/1.2 system-ui,
sans-serif;
color: color-mix(in srgb, var(--gu-curtain-paper) 70%, transparent);
}
.gu-curtain__count {
align-self: flex-end;
font:
900 clamp(4rem, 30cqi, 14rem) / 0.8 system-ui,
sans-serif;
letter-spacing: -0.06em;
font-variant-numeric: tabular-nums;
}
/* Reduced motion: no sliding. The cover fades out and the page stays put. */
@media (prefers-reduced-motion: reduce) {
.gu-curtain__page,
.gu-curtain[data-phase="counting"] .gu-curtain__page {
transform: none;
transition: none;
}
.gu-curtain__layer {
transition: opacity 0.4s linear;
}
.gu-curtain__layer--back {
transition-delay: 0.1s;
}
.gu-curtain[data-phase="lifting"] .gu-curtain__layer {
transform: none;
opacity: 0;
}
}
```
You might also want
Next piece: Date range pickerLoader set
Animations, beginner
Confetti send button
Animations, beginner
Marker highlight
Animations, beginner