Curtain Transition
Between two real pages, an ink panel rises with the name of the next page, then lifts off onto it. Back plays it in reverse. Curved edge or from the top. Chrome, Edge, Safari.
View codeThe logo fills the screen while the page loads, then flies into the header as the screen rolls up. Its line tracks the real load. Any click or key skips it; data-once plays it once per visit.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Add the Kodza Logo Collapse to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-logo-collapse" data-kodza-logo-collapse aria-hidden="true">
<div class="kodza-logo-collapse__screen">
<span class="kodza-logo-collapse__mark"><span class="kodza-logo-collapse__dot"></span>Null Studio</span>
<span class="kodza-logo-collapse__bar"></span>
</div>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Logo Collapse
On the first page of a visit the logo fills the screen while the page loads, then flies to its
place in the header as the screen rolls up and the page plays its entrance. Put the screen at the
top of body, its script right after it, and data-logo-collapse-to on the logo of the header. */
.kodza-logo-collapse {
--kz-logo-collapse-bg: #0a0a0a;
--kz-logo-collapse-fg: #f2f2f0;
--kz-logo-collapse-size: clamp(44px, 8.5vw, 120px); /* the logo while it fills the screen */
--kz-logo-collapse-duration: 1s; /* the flight */
--kz-logo-collapse-ease: cubic-bezier(0.76, 0, 0.24, 1);
--kz-logo-collapse-hold: 0.45s; /* the logo alone, once the page is loaded */
--kz-logo-collapse-enter-ease: cubic-bezier(0.22, 1, 0.36, 1);
position: fixed;
inset: 0;
z-index: 2147483000;
max-width: none; /* a theme's content column must not narrow the screen */
}
.kodza-logo-collapse.is-leaving {
pointer-events: none; /* the page is yours while it appears */
}
/* The screen. The script lays a twin under it, in the colours of the header logo: as the screen
rolls up, its edge cuts the flying logo in two, one colour on each side */
.kodza-logo-collapse__screen {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 32px;
background: var(--kz-logo-collapse-bg);
color: var(--kz-logo-collapse-fg);
}
.kodza-logo-collapse__screen[hidden] {
display: none; /* the twin waits for the flight */
}
.kodza-logo-collapse__screen.is-under {
background: none;
}
.kodza-logo-collapse__screen.is-under .kodza-logo-collapse__bar {
visibility: hidden;
}
/* Your logo, as it is in the header (same text and proportions, or the same SVG): the script
measures both and flies one onto the other */
.kodza-logo-collapse__mark {
position: relative;
display: inline-flex;
align-items: center;
gap: 0.667em;
font-family: var(--kz-font-display, inherit);
font-size: calc(var(--kz-logo-collapse-size) * var(--kz-font-display-scale, 1));
font-weight: var(--kz-font-display-weight, 600);
line-height: 1.2;
letter-spacing: var(--kz-font-display-tracking, -0.02em);
text-transform: var(--kz-font-display-case, none);
white-space: nowrap;
transform-origin: 0 0;
}
.kodza-logo-collapse__dot {
width: 0.667em;
height: 0.667em;
border-radius: var(--kz-radius-pill, 999px);
background: currentColor;
}
.kodza-logo-collapse__mark svg,
.kodza-logo-collapse__mark img {
display: block;
width: auto;
height: 1em;
}
/* How much of the page has loaded: images and fonts, not a timer */
.kodza-logo-collapse__bar {
position: relative;
overflow: hidden;
width: min(220px, 40%);
height: 2px;
border-radius: var(--kz-radius-pill, 999px);
background: color-mix(in srgb, currentColor 18%, transparent);
}
.kodza-logo-collapse__bar::before {
content: "";
position: absolute;
inset: 0;
background: currentColor;
transform: scaleX(var(--kz-logo-collapse-progress, 0));
transform-origin: left;
transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
/* Gone: the page is yours */
.kodza-logo-collapse.is-done {
display: none;
}
@media (prefers-reduced-motion: reduce) {
.kodza-logo-collapse {
display: none;
}
}
/* kodza-guard 0361711e928b — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, on everything the component leaves to it */
.kodza-logo-collapse:not(#_),
.kodza-logo-collapse__screen:not(#_),
.kodza-logo-collapse__mark:not(#_),
.kodza-logo-collapse__dot:not(#_),
.kodza-logo-collapse__bar:not(#_) {
box-sizing: revert;
}
.kodza-logo-collapse__bar:not(#_)::before {
box-sizing: revert;
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Logo Collapse
// On the first page of a visit, the logo fills the screen while the page loads (the line under it
// follows the images and fonts, not a timer), then flies onto the logo of the header, measured
// before and after so it lands on the pixel. The screen rolls up behind it and its edge cuts the
// flying logo in two, screen colours above, header colours below (data-exit="fade": the screen
// fades instead). The page plays its entrance meanwhile (data-enter: label, title, image, the
// rest). data-once plays it once per visit; a click, a key, the wheel or a finger skips the wait.
(() => {
const SELECTOR = '[data-kodza-logo-collapse]';
const KEY = 'kodza-logo-collapse';
const CAP = 3500; // ms the screen waits for the page, at most
const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
const ms = (value, fallback) => {
const n = parseFloat(value);
return Number.isNaN(n) ? fallback : /ms\s*$/.test(value) ? n : n * 1000;
};
const seen = (root) => {
try {
return root.hasAttribute('data-once') && sessionStorage.getItem(KEY) === '1';
} catch {
return false;
}
};
const remember = (root) => {
if (!root.hasAttribute('data-once')) return;
try {
sessionStorage.setItem(KEY, '1');
} catch {
// Storage blocked: the intro plays on every page
}
};
const wait = (time, signal) => new Promise((resolve) => {
const timer = setTimeout(resolve, time);
signal.addEventListener('abort', () => clearTimeout(timer), { once: true });
});
const parsed = () => (document.readyState === 'loading'
? new Promise((resolve) => document.addEventListener('DOMContentLoaded', resolve, { once: true }))
: Promise.resolve());
// The page around the screen: the nearest ancestor that holds the header logo (the body, on a site)
function scopeOf(root) {
for (let el = root.parentElement; el; el = el.parentElement) {
if (el.querySelector('[data-logo-collapse-to]')) return el;
}
return root.parentElement || document.body;
}
// What the page still loads: its images (not the lazy ones, which wait for the scroll) and fonts
function loaded(root, signal, report) {
return parsed().then(() => new Promise((resolve) => {
const images = [...document.images].filter((img) => img.loading !== 'lazy' && !root.contains(img));
const total = images.length + 1;
let done = 0;
const tick = () => {
report(done / total);
if (done >= total) resolve();
};
images.forEach((img) => {
if (img.complete) {
done++;
return;
}
const one = () => {
done++;
tick();
};
img.addEventListener('load', one, { once: true, signal });
img.addEventListener('error', one, { once: true, signal });
});
document.fonts.ready.then(() => {
done++;
tick();
});
tick();
setTimeout(resolve, CAP);
}));
}
// When a cubic-bezier() easing reaches a progress, as a share of its duration
function timeAt(easing, progress) {
const m = /cubic-bezier\(([^)]+)\)/.exec(easing);
if (!m) return progress;
const [x1, y1, x2, y2] = m[1].split(',').map(Number);
const at = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t * t * (1 - t) + t ** 3;
let lo = 0;
let hi = 1;
for (let i = 0; i < 24; i++) {
const mid = (lo + hi) / 2;
if (at(y1, y2, mid) < progress) lo = mid;
else hi = mid;
}
return at(x1, x2, lo);
}
// The entrance of the page: the title rises from behind its own edge, the image opens from the
// bottom, the rest lifts in. Each part starts as the edge of the screen goes past it, from the
// bottom up (`when`), or one after the other once the screen fades
function entrance(root, scope, when, ease) {
const parts = [...scope.querySelectorAll('[data-enter]')].filter((el) => !root.contains(el) && el.getClientRects().length);
return parts.map((el, i) => {
const delay = when(el, i);
const kind = el.dataset.enter;
const frames = kind === 'title'
? [{ transform: 'translateY(100%)', clipPath: 'inset(0 0 100% 0)' }, { transform: 'none', clipPath: 'inset(0)' }]
: kind === 'image'
? [{ transform: 'scale(1.06)', clipPath: 'inset(100% 0 0 0)' }, { transform: 'none', clipPath: 'inset(0)' }]
: [{ opacity: 0, transform: 'translateY(16px)' }, { opacity: 1, transform: 'none' }];
return el.animate(frames, { duration: kind === 'image' ? 1100 : 900, delay, easing: ease, fill: 'backwards' });
});
}
function mount(root, signal) {
const screen = root.querySelector('.kodza-logo-collapse__screen');
const bar = screen.querySelector('.kodza-logo-collapse__bar');
const scope = scopeOf(root);
// The twin under the screen: the same logo, in the colours of the header one
const under = screen.cloneNode(true);
under.classList.add('is-under');
under.setAttribute('aria-hidden', 'true');
root.prepend(under);
const marks = [screen, under].map((layer) => layer.querySelector('.kodza-logo-collapse__mark'));
let running = [];
let run = null; // the play running, aborted by a replay
let hurry = null; // what a click does while the screen waits: leave now
// Played again (kodza:replay), the screen first comes down over the page
const play = (again) => {
if (motion.matches) return root.classList.add('is-done');
run?.abort();
run = new AbortController();
const live = AbortSignal.any ? AbortSignal.any([signal, run.signal]) : signal;
running.forEach((a) => a.cancel());
running = [];
root.classList.remove('is-done', 'is-leaving');
under.hidden = true; // only needed once the logo flies
bar.style.setProperty('--kz-logo-collapse-progress', 0);
const style = getComputedStyle(root);
const duration = ms(style.getPropertyValue('--kz-logo-collapse-duration'), 1000);
const ease = style.getPropertyValue('--kz-logo-collapse-ease').trim() || 'cubic-bezier(0.76, 0, 0.24, 1)';
const enterEase = style.getPropertyValue('--kz-logo-collapse-enter-ease').trim() || 'cubic-bezier(0.22, 1, 0.36, 1)';
const hold = ms(style.getPropertyValue('--kz-logo-collapse-hold'), 450);
const keep = (a) => {
running.push(a);
return a;
};
const drop = again ? 700 : 0;
if (drop) keep(screen.animate([{ clipPath: 'inset(0 0 100% 0)' }, { clipPath: 'inset(0)' }], { duration: drop, easing: ease }));
// The logo rises from behind its own edge, the line comes once it is there
const rise = keep(marks[0].animate([
{ transform: 'translateY(100%)', clipPath: 'inset(0 0 100% 0)' },
{ transform: 'none', clipPath: 'inset(0)' },
], { duration: 900, delay: drop + 100, easing: enterEase, fill: 'backwards' }));
keep(bar.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 500, delay: drop + 500, easing: 'ease-out', fill: 'backwards' }));
let gone = false;
const leave = () => {
if (gone || live.aborted) return;
gone = true;
hurry = null;
running.forEach((a) => a.finish());
root.classList.add('is-leaving');
const target = scope.querySelector('[data-logo-collapse-to]');
const b = target?.getBoundingClientRect();
const lands = b && b.width && b.bottom > 0 && b.top < innerHeight;
const scale = root.getBoundingClientRect().width / root.offsetWidth || 1;
const flight = [];
if (lands) {
const ink = getComputedStyle(target).color;
// Measured on the screen's logo: the twin, still hidden, sits in the very same place
const a = marks[0].getBoundingClientRect();
const k = b.width / a.width;
const x = (b.left - a.left) / scale;
const y = (b.top + b.height / 2 - (a.height * k) / 2 - a.top) / scale;
marks.forEach((mark, i) => {
if (i) mark.style.color = ink;
flight.push(mark.animate([{ transform: 'none' }, { transform: `translate(${x}px, ${y}px) scale(${k})` }], { duration, easing: ease, fill: 'forwards' }));
});
// The header logo waits under the flying one, which lands on it
flight.push(target.animate([{ opacity: 0 }, { opacity: 0 }], { duration, fill: 'forwards' }));
}
under.hidden = !lands; // no logo to land on: it leaves with the screen
flight.push(bar.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 250, easing: 'ease-out', fill: 'forwards' }));
const fade = root.dataset.exit === 'fade';
flight.push(fade
? screen.animate([{ opacity: 1 }, { opacity: 0 }], { duration: duration * 0.8, delay: duration * 0.1, easing: 'ease-in-out', fill: 'forwards' })
: screen.animate([{ clipPath: 'inset(0 0 0 0)' }, { clipPath: 'inset(0 0 100% 0)' }], { duration, easing: ease, fill: 'forwards' }));
const box = root.getBoundingClientRect();
const when = fade
? (el, i) => duration * 0.3 + i * 80
: (el) => {
const r = el.getBoundingClientRect();
const middle = Math.min(Math.max((r.top + r.height / 2 - box.top) / box.height, 0), 1);
return duration * timeAt(ease, 1 - middle);
};
running.push(...flight, ...entrance(root, scope, when, enterEase));
remember(root);
Promise.all(flight.map((a) => a.finished)).then(() => {
if (live.aborted) return;
root.classList.add('is-done');
root.classList.remove('is-leaving');
flight.forEach((a) => a.cancel());
}, () => {});
};
hurry = leave;
Promise.all([
rise.finished,
loaded(root, live, (p) => bar.style.setProperty('--kz-logo-collapse-progress', p)).then(() => wait(600, live)),
]).then(() => wait(hold, live)).then(leave, () => {});
};
// data-once, already seen in this visit: the page is there at once
if (seen(root)) root.classList.add('is-done');
else play();
root.addEventListener('kodza:replay', play, { signal });
// A click, a key, the wheel or a finger: no more waiting
['pointerdown', 'keydown', 'wheel', 'touchstart'].forEach((type) => window.addEventListener(type, () => hurry?.(), { capture: true, passive: true, signal }));
signal.addEventListener('abort', () => {
run?.abort();
running.forEach((a) => a.cancel());
}, { once: true });
}
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load. Each running root
// keeps its markup as written under KODZA, shared by every Kodza script on the page: a Kodza
// component inside another one is saved as written, not half-started, and stopped with it. Two
// components on one root (a reveal on a stat card) both start, and stop together.
const KODZA = Symbol.for('kodza');
const RUNNING = Symbol.for(`kodza ${SELECTOR}`); // a root this component runs on, for every copy of this script
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const attrsOf = (el) => [...el.attributes].map((a) => [a.name, a.value]);
const put = (el, saved) => {
[...el.attributes].forEach((a) => el.removeAttribute(a.name));
saved.attrs.forEach(([name, value]) => el.setAttribute(name, value));
el.innerHTML = saved.html;
};
// The markup inside a root as written: Kodza components already running in it give back their own
const written = (root) => {
const all = [...root.querySelectorAll('*')];
if (!all.some((el) => el[KODZA])) return root.innerHTML;
const copy = root.cloneNode(true);
const twins = copy.querySelectorAll('*');
let last = null;
all.forEach((el, i) => {
if (!el[KODZA] || last?.contains(el)) return;
last = el;
put(twins[i], el[KODZA]);
});
return copy.innerHTML;
};
const init = (scope) => find(scope).forEach((root) => {
// Already running, maybe from another copy of this script. Marked is-ready with no Kodza component
// running on it, a root is a copy of a started one (a cloned slide): it is left as it is
if (root[RUNNING] || (root.classList.contains('is-ready') && !root[KODZA])) return;
// Rendered by React (data-kodza-manual): React starts it, with an init aimed at that markup once
// it has hydrated it. Any earlier start would change markup React has not taken over yet
const owner = root.closest('[data-kodza-manual]');
if (owner && !(scope && owner.contains(scope))) return;
const controller = new AbortController();
// Another Kodza component already running on this root: its markup as written is kept, and the
// two stop together
const before = root[KODZA];
const saved = { html: before ? before.html : written(root), attrs: before ? before.attrs : attrsOf(root), stop: () => destroy(root) };
if (before) before.above = saved;
instances.set(root, { controller, saved, before });
root[KODZA] = saved;
root[RUNNING] = true;
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.saved.above?.stop(); // a Kodza component started after it on the same root stops first
// The Kodza components running inside it stop first: once its markup is put back, their own
// script could not find them any more
root.querySelectorAll('*').forEach((el) => el[KODZA]?.stop());
instance.controller.abort();
delete root[RUNNING];
// Started on top of another one: that one stops next, and puts the markup back
if (instance.before) {
delete instance.before.above;
root[KODZA] = instance.before;
return instance.before.stop();
}
delete root[KODZA];
put(root, instance.saved);
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Logo Collapse, for React. From https://kodza.dev/components/logo-collapse/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: logo-collapse.css and logo-collapse.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
// data-kodza-manual keeps the script from starting it on its own: the effect below does, once
// React has hydrated the markup (on a page that streams in, the script can load first).
// Built from your data (tabs, rows, options)? Put what the markup is made of in the key, as plain
// values (ids, text, numbers): a change starts the script again on fresh markup. What the visitor
// changes (the open tab, the sort, what they type) is the script's: keep it out of the key, follow
// it with onClick or onInput on the root, and change it from your code as a visitor would (click
// the tab; set the field's value, then dispatch a bubbling input event).
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './logo-collapse.css';
export type LogoCollapseProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-logo-collapse-bg"?: string | number;
/** default: #f2f2f0 */
"--kz-logo-collapse-fg"?: string | number;
/** the logo while it fills the screen — default: clamp(44px, 8.5vw, 120px) */
"--kz-logo-collapse-size"?: string | number;
/** the flight — default: 1s */
"--kz-logo-collapse-duration"?: string | number;
/** default: cubic-bezier(0.76, 0, 0.24, 1) */
"--kz-logo-collapse-ease"?: string | number;
/** the logo alone, once the page is loaded — default: 0.45s */
"--kz-logo-collapse-hold"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-logo-collapse-enter-ease"?: string | number;
};
className?: string;
};
export function LogoCollapse({ vars, className, style, ...rest }: LogoCollapseProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-logo-collapse", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./logo-collapse.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
return (
<div data-kodza-logo-collapse="" aria-hidden="true" key={key} {...rest} className={classes} data-kodza-manual style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<div className="kodza-logo-collapse__screen">
<span className="kodza-logo-collapse__mark"><span className="kodza-logo-collapse__dot" />Null Studio</span>
{' '}
<span className="kodza-logo-collapse__bar" />
</div>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.