Hero Exit
A centred title in two big lines. On scroll the scene holds, the lines part, a picture opens between them and tightens into a card, then the next section slides over it.
View codeA centred title and its buttons over a screenshot of the product, leaning back in perspective. On scroll the screen stands up to face you and grows while the title steps back.
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 Hero Screen to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<section class="kodza-hero-screen">
<div class="kodza-hero-screen__scene">
<div class="kodza-hero-screen__copy">
<p class="kodza-hero-screen__eyebrow"><span class="kodza-hero-screen__rise">v2.4 is out · shipped on a Tuesday</span></p>
<h1 class="kodza-hero-screen__title"><span class="kodza-hero-screen__line"><span class="kodza-hero-screen__rise">Show the product.</span></span> <span class="kodza-hero-screen__line"><span class="kodza-hero-screen__rise">Skip the pitch.</span></span></h1>
<div class="kodza-hero-screen__foot">
<p class="kodza-hero-screen__lead">Your real screen, not a Dribbble shot. It leans back, then stands up as they scroll.</p>
<div class="kodza-hero-screen__actions">
<a class="kodza-hero-screen__button kodza-hero-screen__button--ink" href="#">Try it, no card<svg class="kodza-hero-screen__arrow" viewBox="0 0 16 16" aria-hidden="true"><path d="M2.5 8h10.5M9 3.5 13.5 8 9 12.5" /></svg></a>
<a class="kodza-hero-screen__button kodza-hero-screen__button--soft" href="#">What's new</a>
</div>
</div>
</div>
<div class="kodza-hero-screen__stage">
<div class="kodza-hero-screen__device">
<div class="kodza-hero-screen__tilt">
<div class="kodza-hero-screen__shadows" aria-hidden="true"><div class="kodza-hero-screen__shadow kodza-hero-screen__shadow--far"></div><div class="kodza-hero-screen__shadow kodza-hero-screen__shadow--near"></div></div>
<div class="kodza-hero-screen__curtain">
<div class="kodza-hero-screen__hold">
<div class="kodza-hero-screen__frame">
<div class="kodza-hero-screen__glass"><img src="https://kodza.dev/media/kz-grid-2400.webp" alt="The Kodza catalogue: a search field, category filters and a grid of component previews" width="2400" height="1500" /></div>
<div class="kodza-hero-screen__veil"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Hero Screen
A centred title and its buttons over a screenshot of the product, leaning back in
perspective. On scroll the scene holds while the screen stands up to face you and grows to its
real size, passing over the title as it steps back: leaning, the screen sits in shade under a
long soft shadow; upright, it lights up and the shadow tucks in. Then the page goes on.
Without the script, or with reduced motion, nothing pins: the title, then the screen, upright.
Everything is tuned with the --kz-hero-screen-* variables. */
.kodza-hero-screen {
--kz-hero-screen-ink: #0a0a0a;
--kz-hero-screen-paper: #f2f2f0;
--kz-hero-screen-dim: rgba(10, 10, 10, 0.62);
--kz-hero-screen-faint: rgba(10, 10, 10, 0.6);
--kz-hero-screen-soft: rgba(10, 10, 10, 0.07);
--kz-hero-screen-bg: transparent;
--kz-hero-screen-bezel: #fff; /* the frame around the screenshot */
--kz-hero-screen-edge: rgba(10, 10, 10, 0.1);
--kz-hero-screen-shadow-far: 0 60px 110px -34px rgba(10, 10, 10, 0.34), 0 24px 48px -24px rgba(10, 10, 10, 0.16); /* leaning back */
--kz-hero-screen-shadow-near: 0 1px 2px rgba(10, 10, 10, 0.06), 0 22px 48px -22px rgba(10, 10, 10, 0.24); /* upright */
--kz-hero-screen-veil: linear-gradient(rgba(10, 10, 10, 0.14), rgba(10, 10, 10, 0.03) 70%); /* the shade on the screen while it leans */
--kz-hero-screen-width: 1240px;
--kz-hero-screen-gutter: clamp(16px, 4vw, 40px);
--kz-hero-screen-pad-y: clamp(20px, 3svh, 40px);
--kz-hero-screen-size: clamp(36px, min(6.4cqi, 9.4svh), 96px); /* the title lines */
--kz-hero-screen-ratio: 1.6; /* the screenshot's width / height */
--kz-hero-screen-tilt: 24deg; /* how far the screen leans back at rest */
--kz-hero-screen-shrink: 0.86; /* its scale at rest: it grows to full size */
--kz-hero-screen-depth: 1600px; /* the perspective: shorter is stronger */
--kz-hero-screen-radius: 18px;
--kz-hero-screen-top: 0px; /* height of a fixed site header: the scene pins under it */
--kz-hero-screen-distance: 140svh; /* how long the scene holds */
--kz-hero-screen-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
--kz-hero-screen-ease: cubic-bezier(0.22, 1, 0.36, 1);
container: kodza-hero-screen / inline-size;
position: relative;
box-sizing: border-box;
width: 100%;
color: var(--kz-hero-screen-ink);
}
.kodza-hero-screen__scene {
position: relative;
background: var(--kz-hero-screen-bg);
}
.kodza-hero-screen__copy {
position: relative;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
max-width: calc(var(--kz-hero-screen-width) + 2 * var(--kz-hero-screen-gutter));
margin: 0 auto;
padding: clamp(72px, 9vw, 140px) max(var(--kz-hero-screen-gutter), env(safe-area-inset-right, 0px)) clamp(44px, 5vw, 72px) max(var(--kz-hero-screen-gutter), env(safe-area-inset-left, 0px));
text-align: center;
transform-origin: 50% 0;
}
.kodza-hero-screen__eyebrow {
overflow: hidden;
margin: 0 0 clamp(16px, 2cqi, 26px);
font-family: var(--kz-hero-screen-mono);
font-size: 12.5px;
font-weight: 500;
line-height: 1.4;
letter-spacing: 0.02em;
color: var(--kz-hero-screen-faint);
}
.kodza-hero-screen__rise {
display: block;
}
.kodza-hero-screen__title {
margin: 0 0 clamp(20px, 2.4cqi, 30px);
font-size: var(--kz-hero-screen-size);
font-weight: 700;
line-height: 1;
letter-spacing: -0.05em;
}
/* Each line is a mask: the words rise out of it on arrival */
.kodza-hero-screen__line {
display: block;
overflow: hidden;
padding-bottom: 0.08em;
margin-bottom: -0.08em;
white-space: nowrap;
}
.kodza-hero-screen__foot {
display: flex;
flex-direction: column;
align-items: center;
gap: 28px;
}
.kodza-hero-screen__lead {
max-width: 40ch;
margin: 0;
font-size: clamp(16px, 1.3cqi, 18px);
line-height: 1.55;
color: var(--kz-hero-screen-dim);
text-wrap: balance;
}
.kodza-hero-screen__actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
.kodza-hero-screen__button {
position: relative;
isolation: isolate;
overflow: hidden;
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 10px;
height: 52px;
padding: 0 26px;
border: 0;
border-radius: 999px;
font-family: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
white-space: nowrap;
text-decoration: none;
cursor: pointer;
}
.kodza-hero-screen__button:focus-visible {
outline: 2px solid var(--kz-hero-screen-ink);
outline-offset: 3px;
}
/* Solid: the arrow steps forward on hover */
.kodza-hero-screen__button--ink {
background: var(--kz-hero-screen-ink);
color: var(--kz-hero-screen-paper);
}
.kodza-hero-screen__arrow {
flex: none;
width: 16px;
height: 16px;
fill: none;
stroke: currentColor;
stroke-width: 1.5;
stroke-linecap: round;
stroke-linejoin: round;
transition: transform 0.3s var(--kz-hero-screen-ease);
}
/* Soft: ink rises from the bottom edge on hover */
.kodza-hero-screen__button--soft {
background: var(--kz-hero-screen-soft);
color: var(--kz-hero-screen-ink);
transition: color 0.4s var(--kz-hero-screen-ease);
}
.kodza-hero-screen__button--soft::before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: inherit;
background: var(--kz-hero-screen-ink);
transform: translateY(101%);
transition: transform 0.4s var(--kz-hero-screen-ease);
}
@media (hover: hover) {
.kodza-hero-screen__button--ink:hover .kodza-hero-screen__arrow {
transform: translateX(4px);
}
.kodza-hero-screen__button--soft:hover {
color: var(--kz-hero-screen-paper);
}
.kodza-hero-screen__button--soft:hover::before {
transform: none;
}
}
/* The screen, without the script: upright under the words */
.kodza-hero-screen__stage {
box-sizing: border-box;
padding: 0 max(var(--kz-hero-screen-gutter), env(safe-area-inset-right, 0px)) clamp(56px, 7vw, 104px) max(var(--kz-hero-screen-gutter), env(safe-area-inset-left, 0px));
pointer-events: none;
}
.kodza-hero-screen__device {
width: min(100%, var(--kz-hero-screen-width));
margin: 0 auto;
transform-origin: 50% 0;
}
/* The script leans it back from its top edge, in its own perspective */
.kodza-hero-screen__tilt {
position: relative;
transform-origin: 50% 0;
}
.kodza-hero-screen__shadow {
position: absolute;
inset: 0;
border-radius: var(--kz-hero-screen-radius);
}
.kodza-hero-screen__shadow--far {
box-shadow: var(--kz-hero-screen-shadow-far);
opacity: 0;
}
.kodza-hero-screen__shadow--near {
box-shadow: var(--kz-hero-screen-shadow-near);
}
/* On arrival the frame opens from its top edge down: the curtain slides down while its content
slides up by as much, so the screen itself stays put */
.kodza-hero-screen__curtain {
position: relative;
overflow: hidden;
border-radius: var(--kz-hero-screen-radius);
}
.kodza-hero-screen__frame {
position: relative;
box-sizing: border-box;
padding: clamp(4px, 0.5cqi, 7px);
border: 1px solid var(--kz-hero-screen-edge);
border-radius: var(--kz-hero-screen-radius);
background: var(--kz-hero-screen-bezel);
}
.kodza-hero-screen__glass {
overflow: hidden;
border-radius: calc(var(--kz-hero-screen-radius) - clamp(4px, 0.5cqi, 7px) - 1px);
}
.kodza-hero-screen__glass img {
display: block;
width: 100%;
height: auto;
max-width: none;
}
.kodza-hero-screen__veil {
position: absolute;
inset: 0;
border-radius: inherit;
background: var(--kz-hero-screen-veil);
opacity: 0;
}
/* With the script and motion: a tall section, the scene pinned inside it, the copy at the top and
the screen in its place at the centre (the script leans it back from there) */
@media (prefers-reduced-motion: no-preference) {
.kodza-hero-screen.is-ready {
height: calc(100svh - var(--kz-hero-screen-top) + var(--kz-hero-screen-distance));
}
.kodza-hero-screen.is-ready .kodza-hero-screen__scene {
position: sticky;
top: var(--kz-hero-screen-top);
overflow: hidden;
overflow: clip;
height: calc(100svh - var(--kz-hero-screen-top));
}
.kodza-hero-screen.is-ready .kodza-hero-screen__copy {
padding-top: clamp(28px, 11svh, 120px);
padding-bottom: clamp(24px, 5.5svh, 56px);
}
.kodza-hero-screen.is-ready .kodza-hero-screen__stage {
position: absolute;
inset: 0;
z-index: 1;
display: grid;
place-items: center;
padding-top: var(--kz-hero-screen-pad-y);
padding-bottom: var(--kz-hero-screen-pad-y);
}
.kodza-hero-screen.is-ready .kodza-hero-screen__device {
width: min(100%, var(--kz-hero-screen-width), (100svh - var(--kz-hero-screen-top) - 2 * var(--kz-hero-screen-pad-y)) * var(--kz-hero-screen-ratio));
}
.kodza-hero-screen.is-ready .kodza-hero-screen__shadow--far,
.kodza-hero-screen.is-ready .kodza-hero-screen__veil {
opacity: 1;
}
.kodza-hero-screen.is-ready .kodza-hero-screen__shadow--near {
opacity: 0;
}
/* Waiting for its entrance: the script sets is-shown and plays the motion in the same frame */
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__rise {
transform: translateY(105%);
}
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__curtain {
transform: translateY(-100%);
}
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__hold {
transform: translateY(100%);
}
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__lead,
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__actions,
.kodza-hero-screen.is-ready:not(.is-shown) .kodza-hero-screen__shadows {
opacity: 0;
}
/* A phone: a whole desktop screen would be too small to read, so it lands bigger, from the left
gutter, and runs off the right edge (the scene cuts it) */
@container kodza-hero-screen (max-width: 640px) {
.kodza-hero-screen.is-ready .kodza-hero-screen__device {
justify-self: start;
width: 170%;
}
}
}
/* A phone: the buttons share the row */
@container kodza-hero-screen (max-width: 520px) {
.kodza-hero-screen__foot {
align-self: stretch;
}
.kodza-hero-screen__button {
flex: 1 1 auto;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-hero-screen *,
.kodza-hero-screen *::before,
.kodza-hero-screen *::after {
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
/* kodza-guard e146b4536f11 — 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, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */
:where(.kodza-hero-screen__eyebrow):not(#_),
:where(.kodza-hero-screen__title):not(#_),
:where(.kodza-hero-screen__lead):not(#_),
:where(.kodza-hero-screen__glass img:where(:not([class*="kodza-"]))):not(#_) {
transition-duration: revert;
}
:where(.kodza-hero-screen__button):not(#_) {
outline: revert;
transition: revert;
outline-offset: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-hero-screen__scene:not(#_),
.kodza-hero-screen__rise:not(#_),
.kodza-hero-screen__line:not(#_),
.kodza-hero-screen__foot:not(#_),
.kodza-hero-screen__actions:not(#_),
.kodza-hero-screen__device:not(#_),
.kodza-hero-screen__tilt:not(#_),
.kodza-hero-screen__shadows:not(#_),
.kodza-hero-screen__shadow:not(#_),
.kodza-hero-screen__curtain:not(#_),
.kodza-hero-screen__hold:not(#_),
.kodza-hero-screen__glass:not(#_),
.kodza-hero-screen__veil:not(#_) {
box-sizing: revert;
}
.kodza-hero-screen__eyebrow:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-hero-screen__title:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-style: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-hero-screen__lead:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-height: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-hero-screen__button:not(#_) {
margin: revert;
list-style: revert;
float: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-hero-screen__arrow:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-hero-screen__glass img:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
transition-property: revert;
transition-timing-function: revert;
transition-delay: revert;
}
.kodza-hero-screen__eyebrow:not(#_):where(:not([hidden])),
.kodza-hero-screen__title:not(#_):where(:not([hidden])),
.kodza-hero-screen__lead:not(#_):where(:not([hidden])),
.kodza-hero-screen__arrow:not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-hero-screen__eyebrow:not(#_):where([hidden]),
.kodza-hero-screen__title:not(#_):where([hidden]),
.kodza-hero-screen__lead:not(#_):where([hidden]),
.kodza-hero-screen__arrow:not(#_):where([hidden]) {
display: none;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-hero-screen__eyebrow:not(#_) {
margin: 0 0 clamp(16px, 2cqi, 26px);
font-family: var(--kz-hero-screen-mono);
font-size: 12.5px;
font-weight: 500;
line-height: 1.4;
letter-spacing: 0.02em;
color: var(--kz-hero-screen-faint);
}
.kodza-hero-screen__title:not(#_) {
margin: 0 0 clamp(20px, 2.4cqi, 30px);
font-size: var(--kz-hero-screen-size);
font-weight: 700;
line-height: 1;
letter-spacing: -0.05em;
}
.kodza-hero-screen__lead:not(#_) {
max-width: 40ch;
margin: 0;
font-size: clamp(16px, 1.3cqi, 18px);
line-height: 1.55;
color: var(--kz-hero-screen-dim);
}
.kodza-hero-screen__button:not(#_) {
position: relative;
box-sizing: border-box;
display: inline-flex;
padding: 0 26px;
border: 0;
border-radius: 999px;
font-family: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
text-decoration: none;
}
.kodza-hero-screen__button:focus-visible:not(#_) {
outline: 2px solid var(--kz-hero-screen-ink);
outline-offset: 3px;
}
.kodza-hero-screen__button--ink:not(#_) {
background: var(--kz-hero-screen-ink);
color: var(--kz-hero-screen-paper);
}
.kodza-hero-screen__arrow:not(#_) {
transition: transform 0.3s var(--kz-hero-screen-ease);
}
.kodza-hero-screen__button--soft:not(#_) {
background: var(--kz-hero-screen-soft);
color: var(--kz-hero-screen-ink);
transition: color 0.4s var(--kz-hero-screen-ease);
}
@media (hover: hover) {
.kodza-hero-screen__button--soft:hover:not(#_) {
color: var(--kz-hero-screen-paper);
}
}
.kodza-hero-screen__glass img:not(#_) {
display: block;
max-width: none;
}
@media (prefers-reduced-motion: reduce) {
.kodza-hero-screen *:where(p, h1, a, svg, img):not(#_) {
transition-duration: 0.01ms !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Hero Screen
// Plays the entrance of Hero Split once the section is in view (the label and title lines rise
// out of their masks, the screen opens from its top edge down, the rest follows), then hands over
// to the scroll: the scene pins while the screen, leaning back under the title, stands up to face
// you and grows to its real size, passing over the title as it steps back. Leaning, the screen
// sits in shade under a long soft shadow; upright, it lights up and the shadow tucks in. Every move
// is a paused animation set from the scroll: scrolling back up plays it in reverse.
// "kodza:replay" plays the entrance again.
(() => {
const SELECTOR = '.kodza-hero-screen';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const GLIDE = 'cubic-bezier(0.6, 0, 0.1, 1)'; // slow start, long settle
const SOFT = 'cubic-bezier(0.25, 1, 0.5, 1)';
const TRAVEL = 'cubic-bezier(0.45, 0, 0.55, 1)'; // the moves on the scroll: gentle, a mouse wheel goes by notches
const decoded = (root) => Promise.all([...root.querySelectorAll('img')].map((img) => img.decode().catch(() => {})));
// ---------- Scroll engine (begin) ----------
// The same block in every hero that plays on scroll: copy it as is, write only the timeline.
// `root` is a tall track and `scene` sticks inside it (position: sticky, in the CSS); the
// progress runs from 0, the scene just pinned, to 1, about to unpin. `timeline()` returns
// tracks, [element, keyframes, from, to] with from and to in progress; each becomes a paused
// Web Animation whose time follows the scroll, smoothed by a requestAnimationFrame loop that
// sleeps once it has caught up. The tracks are built again when `scene` or an element of
// `watch` changes size, so `timeline()` measures there.
function scrub(root, scene, signal, timeline, watch = []) {
const SPAN = 1000;
let tracks = [];
let live = false;
let now = 0;
let target = 0;
let frame = 0;
let last = 0;
const geometry = () => {
const box = root.getBoundingClientRect();
return {
top: box.top,
scale: box.height / root.offsetHeight || 1, // a parent scaled by transform
run: root.offsetHeight - scene.offsetHeight,
stick: parseFloat(getComputedStyle(scene).top) || 0,
};
};
const progress = () => {
const { top, scale, run, stick } = geometry();
return run > 0 ? Math.min(1, Math.max(0, (stick - top / scale) / run)) : 0;
};
const seek = () => tracks.forEach((a) => { a.currentTime = now * SPAN; });
const tick = (time) => {
const dt = last ? Math.min(time - last, 64) : 16;
last = time;
now += (target - now) * (1 - Math.exp(-dt / 70));
if (Math.abs(target - now) < 0.0004) now = target;
seek();
frame = now === target ? 0 : requestAnimationFrame(tick);
if (!frame) last = 0;
};
const update = () => {
if (!live) return;
target = progress();
if (!frame) frame = requestAnimationFrame(tick);
};
const clear = () => {
tracks.forEach((a) => a.cancel());
tracks = [];
};
const build = () => {
clear();
if (!live) return;
tracks = timeline().filter(([el]) => el).map(([el, keyframes, from, to]) => {
const a = el.animate(keyframes, { duration: (to - from) * SPAN, delay: from * SPAN, endDelay: (1 - to) * SPAN, fill: 'both' });
a.pause();
return a;
});
seek();
update();
};
const stop = () => {
live = false;
cancelAnimationFrame(frame);
frame = last = now = 0;
clear();
};
// Scrolls the page so the progress is at least `p` (a focused control must show)
const reveal = (p) => {
const { top, scale, run, stick } = geometry();
if (run > 0 && progress() < p) window.scrollBy(0, top - (stick - p * run) * scale);
};
document.addEventListener('scroll', update, { passive: true, capture: true, signal });
window.addEventListener('resize', update, { passive: true, signal });
let resized = 0;
const ro = new ResizeObserver(() => {
cancelAnimationFrame(resized);
resized = requestAnimationFrame(build);
});
[scene, ...watch].forEach((el) => el && ro.observe(el));
signal.addEventListener('abort', () => {
ro.disconnect();
cancelAnimationFrame(resized);
stop();
});
return {
start() {
live = true;
build();
},
stop,
progress,
reveal,
};
}
// ---------- Scroll engine (end) ----------
// One instance, with its own state: two copies on a page never interfere. Everything it
// starts is tied to `signal` (listeners get { signal }, observers and timers stop on its
// 'abort' event), so kodza:destroy stops it all.
function mount(root, signal) {
if (reduceMotion) return root.classList.add('is-shown');
const q = (s) => root.querySelector(s);
const scene = q('.kodza-hero-screen__scene');
const copy = q('.kodza-hero-screen__copy');
const device = q('.kodza-hero-screen__device');
const tilt = q('.kodza-hero-screen__tilt');
const lines = [...root.querySelectorAll('.kodza-hero-screen__line')];
const setting = (name, fallback) => {
const value = parseFloat(getComputedStyle(root).getPropertyValue(`--kz-hero-screen-${name}`));
return Number.isFinite(value) ? value : fallback;
};
// The screen sits in its place at the centre of the scene (the CSS puts it there). At rest it
// leans back from its top edge, smaller, that edge just under the copy: these are the
// transforms that take it there, set inline so the entrance plays on the leaning screen.
// Layout boxes only (offsetTop…): they ignore transforms, so a scaled page changes nothing.
const measure = () => {
const rest = {
device: `translateY(${copy.offsetTop + copy.offsetHeight - device.offsetTop}px) scale(${setting('shrink', 0.86)})`,
tilt: `perspective(${setting('depth', 1600)}px) rotateX(${setting('tilt', 24)}deg)`,
};
device.style.transform = rest.device;
tilt.style.transform = rest.tilt;
return rest;
};
// The scroll part, in progress: the screen stands up first, then grows into its place, and
// holds there for the last stretch before the page goes on
const timeline = () => {
const rest = measure();
const fade = (el, from, to, start, end) => [el, [{ opacity: from, easing: TRAVEL }, { opacity: to }], start, end];
// The copy steps back as the screen comes up over it, its lowest lines first
const words = [q('.kodza-hero-screen__actions'), q('.kodza-hero-screen__lead'), ...[...lines].reverse(), q('.kodza-hero-screen__eyebrow')];
return [
[tilt, [{ transform: rest.tilt, easing: TRAVEL }, { transform: rest.tilt.replace(/rotateX\([^)]*\)/, 'rotateX(0deg)') }], 0, 0.62],
[device, [{ transform: rest.device, easing: TRAVEL }, { transform: 'translateY(0px) scale(1)' }], 0, 0.74],
// Leaning, it sits in shade under a long soft shadow; facing you, it lights up and the
// shadow tucks in under it
fade(q('.kodza-hero-screen__veil'), 1, 0, 0, 0.62),
fade(q('.kodza-hero-screen__shadow--far'), 1, 0, 0.05, 0.6),
fade(q('.kodza-hero-screen__shadow--near'), 0, 1, 0.25, 0.72),
[copy, [
{ transform: 'translateY(0px) scale(1)', easing: TRAVEL },
{ transform: `translateY(${-0.06 * scene.clientHeight}px) scale(0.9)` },
], 0, 0.6],
...words.map((el, i) => fade(el, 1, 0, i * 0.035, 0.3 + i * 0.045)),
];
};
const pin = scrub(root, scene, signal, timeline, [copy]);
let running = [];
const stop = () => {
running.forEach((a) => a.cancel());
running = [];
};
const animate = (el, keyframes, options) => {
if (el) running.push(el.animate(keyframes, { easing: GLIDE, fill: 'backwards', ...options }));
};
const rise = (el, delay, duration) => animate(el, [{ transform: 'translateY(105%)' }, { transform: 'none' }], { duration, delay });
// Scrolling during the entrance hurries it, so the scroll takes over without a wait
const hurry = () => {
if (running.length && !root.classList.contains('is-live') && pin.progress() > 0) running.forEach((a) => a.updatePlaybackRate(4));
};
const play = async () => {
await decoded(root);
if (signal.aborted) return;
stop();
pin.stop();
root.classList.remove('is-live');
root.classList.add('is-shown');
measure();
rise(q('.kodza-hero-screen__eyebrow .kodza-hero-screen__rise'), 0, 1000);
lines.forEach((l, i) => rise(l.querySelector(':scope > .kodza-hero-screen__rise'), 110 + i * 125, 1170));
// The screen opens from its top edge down, settling from a slight zoom
animate(q('.kodza-hero-screen__curtain'), [{ transform: 'translateY(-100%)' }, { transform: 'none' }], { duration: 1350, delay: 200 });
animate(q('.kodza-hero-screen__hold'), [{ transform: 'translateY(100%)' }, { transform: 'none' }], { duration: 1350, delay: 200 });
animate(q('.kodza-hero-screen__glass img'), [{ transform: 'scale(1.2)' }, { transform: 'none' }], { duration: 2000, delay: 200, easing: SOFT });
// Its shadow comes once it is mostly open, never around an empty frame
animate(q('.kodza-hero-screen__shadows'), [{ opacity: 0 }, { opacity: 1 }], { duration: 1000, delay: 1000, easing: SOFT });
[q('.kodza-hero-screen__lead'), q('.kodza-hero-screen__actions')].forEach((el, i) => {
animate(el, [{ opacity: 0, transform: 'translateY(20px)' }, { opacity: 1, transform: 'none' }], { duration: 900, delay: 700 + i * 110, easing: SOFT });
});
hurry();
const entrance = running;
Promise.all(entrance.map((a) => a.finished)).then(() => {
if (entrance !== running || signal.aborted) return;
root.classList.add('is-live');
pin.start();
}, () => {});
};
root.addEventListener('kodza:replay', play, { signal });
document.addEventListener('scroll', hurry, { passive: true, capture: true, signal });
// Tabbing back to a button scrolls back to where it shows: the hero, whole
q('.kodza-hero-screen__foot').addEventListener('focusin', () => {
if (pin.progress() <= 0) return;
const box = root.getBoundingClientRect();
const k = box.height / root.offsetHeight || 1;
window.scrollBy(0, box.top - (parseFloat(getComputedStyle(scene).top) || 0) * k);
}, { signal });
signal.addEventListener('abort', stop);
const io = new IntersectionObserver((entries) => {
if (!entries.some((entry) => entry.isIntersecting)) return;
io.disconnect();
play();
}, { rootMargin: '0px 0px -15% 0px' });
signal.addEventListener('abort', () => io.disconnect());
Promise.all([document.fonts?.ready, decoded(root)]).then(() => {
if (!signal.aborted) io.observe(root);
});
}
// 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.
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const init = (scope) => find(scope).forEach((root) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
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.controller.abort();
[...root.attributes].forEach((a) => root.removeAttribute(a.name));
instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
root.innerHTML = instance.html;
});
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 — Hero Screen, for React. From https://kodza.dev/components/hero-screen/
// 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: hero-screen.css and hero-screen.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.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './hero-screen.css';
export type HeroScreenProps = Omit<ComponentPropsWithoutRef<'section'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-hero-screen-ink"?: string | number;
/** default: #f2f2f0 */
"--kz-hero-screen-paper"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-hero-screen-dim"?: string | number;
/** default: rgba(10, 10, 10, 0.6) */
"--kz-hero-screen-faint"?: string | number;
/** default: rgba(10, 10, 10, 0.07) */
"--kz-hero-screen-soft"?: string | number;
/** default: transparent */
"--kz-hero-screen-bg"?: string | number;
/** the frame around the screenshot — default: #fff */
"--kz-hero-screen-bezel"?: string | number;
/** default: rgba(10, 10, 10, 0.1) */
"--kz-hero-screen-edge"?: string | number;
/** leaning back — default: 0 60px 110px -34px rgba(10, 10, 10, 0.34), 0 24px 48px -24px rgba(10, 10, 10, 0.16) */
"--kz-hero-screen-shadow-far"?: string | number;
/** upright — default: 0 1px 2px rgba(10, 10, 10, 0.06), 0 22px 48px -22px rgba(10, 10, 10, 0.24) */
"--kz-hero-screen-shadow-near"?: string | number;
/** the shade on the screen while it leans — default: linear-gradient(rgba(10, 10, 10, 0.14), rgba(10, 10, 10, 0.03) 70%) */
"--kz-hero-screen-veil"?: string | number;
/** default: 1240px */
"--kz-hero-screen-width"?: string | number;
/** default: clamp(16px, 4vw, 40px) */
"--kz-hero-screen-gutter"?: string | number;
/** default: clamp(20px, 3svh, 40px) */
"--kz-hero-screen-pad-y"?: string | number;
/** the title lines — default: clamp(36px, min(6.4cqi, 9.4svh), 96px) */
"--kz-hero-screen-size"?: string | number;
/** the screenshot's width / height — default: 1.6 */
"--kz-hero-screen-ratio"?: string | number;
/** how far the screen leans back at rest — default: 24deg */
"--kz-hero-screen-tilt"?: string | number;
/** its scale at rest: it grows to full size — default: 0.86 */
"--kz-hero-screen-shrink"?: string | number;
/** the perspective: shorter is stronger — default: 1600px */
"--kz-hero-screen-depth"?: string | number;
/** default: 18px */
"--kz-hero-screen-radius"?: string | number;
/** height of a fixed site header: the scene pins under it — default: 0px */
"--kz-hero-screen-top"?: string | number;
/** how long the scene holds — default: 140svh */
"--kz-hero-screen-distance"?: string | number;
/** default: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace */
"--kz-hero-screen-mono"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-hero-screen-ease"?: string | number;
};
className?: string;
};
export function HeroScreen({ vars, className, style, ...rest }: HeroScreenProps) {
const ref = useRef<ComponentRef<'section'>>(null);
const classes = ["kodza-hero-screen", 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('./hero-screen.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 (
<section key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<div className="kodza-hero-screen__scene">
<div className="kodza-hero-screen__copy">
<p className="kodza-hero-screen__eyebrow">
<span className="kodza-hero-screen__rise">v2.4 is out · shipped on a Tuesday</span>
</p>
<h1 className="kodza-hero-screen__title">
<span className="kodza-hero-screen__line">
<span className="kodza-hero-screen__rise">Show the product.</span>
</span>
{' '}
<span className="kodza-hero-screen__line">
<span className="kodza-hero-screen__rise">Skip the pitch.</span>
</span>
</h1>
<div className="kodza-hero-screen__foot">
<p className="kodza-hero-screen__lead">Your real screen, not a Dribbble shot. It leans back, then stands up as they scroll.</p>
<div className="kodza-hero-screen__actions">
<a className="kodza-hero-screen__button kodza-hero-screen__button--ink" href="#">Try it, no card<svg className="kodza-hero-screen__arrow" viewBox="0 0 16 16" aria-hidden="true"> <path d="M2.5 8h10.5M9 3.5 13.5 8 9 12.5" /> </svg></a>
{' '}
<a className="kodza-hero-screen__button kodza-hero-screen__button--soft" href="#">What's new</a>
</div>
</div>
</div>
<div className="kodza-hero-screen__stage">
<div className="kodza-hero-screen__device">
<div className="kodza-hero-screen__tilt">
<div className="kodza-hero-screen__shadows" aria-hidden="true">
<div className="kodza-hero-screen__shadow kodza-hero-screen__shadow--far" />
<div className="kodza-hero-screen__shadow kodza-hero-screen__shadow--near" />
</div>
<div className="kodza-hero-screen__curtain">
<div className="kodza-hero-screen__hold">
<div className="kodza-hero-screen__frame">
<div className="kodza-hero-screen__glass">
<img src="https://kodza.dev/media/kz-grid-2400.webp" alt="The Kodza catalogue: a search field, category filters and a grid of component previews" width="2400" height="1500" />
</div>
<div className="kodza-hero-screen__veil" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.