Hover Nav
A pill of links where the highlight slides under the pointer and settles back on the current page. The ink version turns the text white right at its edges.
View codePress Menu and the page swings down on its hinge like a trapdoor, showing the menu underneath: links rise as the edge passes them, an image follows your pointer. Closing replays it backwards. No GSAP.
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 Trapdoor Menu to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-trapdoor">
<button class="kodza-trapdoor__toggle" type="button" aria-haspopup="dialog" aria-expanded="false"><span class="kodza-trapdoor__lines" aria-hidden="true"></span>Menu</button>
<div class="kodza-trapdoor__panel" role="dialog" aria-modal="true" aria-label="Menu" tabindex="-1" hidden>
<div class="kodza-trapdoor__bar">
<p class="kodza-trapdoor__label">5 doors, no stairs</p>
<button class="kodza-trapdoor__close" type="button"><span class="kodza-trapdoor__cross" aria-hidden="true"></span>Close</button>
</div>
<div class="kodza-trapdoor__stage">
<nav class="kodza-trapdoor__nav" aria-label="Main">
<a class="kodza-trapdoor__link" href="#"><span class="kodza-trapdoor__index">01</span><span class="kodza-trapdoor__mask"><span class="kodza-trapdoor__word">Work</span></span><span class="kodza-trapdoor__meta">12 shipped</span></a>
<a class="kodza-trapdoor__link" href="#"><span class="kodza-trapdoor__index">02</span><span class="kodza-trapdoor__mask"><span class="kodza-trapdoor__word">Studio</span></span><span class="kodza-trapdoor__meta">est. 2019</span></a>
<a class="kodza-trapdoor__link" href="#"><span class="kodza-trapdoor__index">03</span><span class="kodza-trapdoor__mask"><span class="kodza-trapdoor__word">Journal</span></span><span class="kodza-trapdoor__meta">weekly-ish</span></a>
<a class="kodza-trapdoor__link" href="#"><span class="kodza-trapdoor__index">04</span><span class="kodza-trapdoor__mask"><span class="kodza-trapdoor__word">Lab</span></span><span class="kodza-trapdoor__meta">may break</span></a>
<a class="kodza-trapdoor__link" href="#"><span class="kodza-trapdoor__index">05</span><span class="kodza-trapdoor__mask"><span class="kodza-trapdoor__word">Contact</span></span><span class="kodza-trapdoor__meta">replies in a day</span></a>
</nav>
<div class="kodza-trapdoor__media" aria-hidden="true">
<div class="kodza-trapdoor__figure">
<div class="kodza-trapdoor__frame">
<img class="kodza-trapdoor__image" src="https://kodza.dev/media/kz-columns-1400.webp" alt="" width="1120" height="1400" decoding="async">
<img class="kodza-trapdoor__image" src="https://kodza.dev/media/kz-block-1400.webp" alt="" width="1120" height="1400" decoding="async">
<img class="kodza-trapdoor__image" src="https://kodza.dev/media/kz-stack-1400.webp" alt="" width="1400" height="1050" decoding="async">
<img class="kodza-trapdoor__image" src="https://kodza.dev/media/kz-float-1400.webp" alt="" width="1400" height="933" decoding="async">
<img class="kodza-trapdoor__image" src="https://kodza.dev/media/kz-steps-1400.webp" alt="" width="1400" height="933" decoding="async">
</div>
<p class="kodza-trapdoor__caption"><span>display: grid</span><span>display: block</span><span>z-index: 9999</span><span>float: left</span><span>steps(5, end)</span></p>
</div>
</div>
<div class="kodza-trapdoor__info">
<p>Open for new work · Q1 2027</p>
<p class="kodza-trapdoor__socials"><a href="#">GitHub</a><a href="#">X</a><a href="#">RSS</a></p>
<p class="kodza-trapdoor__hint">Esc puts the floor back.</p>
</div>
</div>
</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 — Trapdoor Menu
The page tips back on its bottom edge like a trapdoor and shows the menu underneath: the rows
draw in, the links rise from their masks as the edge uncovers them, the image follows the link
you point at, then the small print. Closing plays it all backwards.
Mark the wrapper of your site with data-trapdoor-page, or name it on the menu with
data-page="…" (the wrapper of most WordPress themes is found on its own).
Everything is tuned with the --kz-trapdoor-* variables. */
.kodza-trapdoor {
--kz-trapdoor-bg: #0a0a0a; /* the menu, under the page */
--kz-trapdoor-fg: #f2f2f0;
--kz-trapdoor-muted: rgba(242, 242, 240, 0.62);
--kz-trapdoor-line: rgba(242, 242, 240, 0.16);
--kz-trapdoor-ink: #0a0a0a; /* the Menu button, on the page */
--kz-trapdoor-on-ink: #ffffff;
--kz-trapdoor-page: auto; /* the page colour while it tips; auto = the first background above it */
--kz-trapdoor-top: calc(var(--wp-admin--admin-bar--height, 0px) + 20px); /* match your header, so Close lands right where Menu was (below the WordPress admin bar) */
--kz-trapdoor-side: 24px;
--kz-trapdoor-size: clamp(28px, min(7.4cqw, calc(16cqh - 46px)), 104px);
--kz-trapdoor-angle: 84deg; /* how far the page tips back */
--kz-trapdoor-shade: 0.6; /* how dark it gets on the way down */
--kz-trapdoor-duration: 1.1s;
--kz-trapdoor-ease: cubic-bezier(0.76, 0, 0.24, 1);
display: inline-block;
}
.kodza-trapdoor__toggle,
.kodza-trapdoor__close {
display: inline-flex;
align-items: center;
gap: 10px;
height: 40px;
margin: 0;
padding: 0 18px 0 16px;
border: 0;
border-radius: 999px;
font: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
letter-spacing: -0.01em;
white-space: nowrap;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-trapdoor__toggle {
background: var(--kz-trapdoor-ink);
color: var(--kz-trapdoor-on-ink);
}
.kodza-trapdoor__close {
background: var(--kz-trapdoor-fg);
color: var(--kz-trapdoor-bg);
}
.kodza-trapdoor__toggle:focus-visible {
outline: 2px solid var(--kz-trapdoor-ink);
outline-offset: 3px;
}
.kodza-trapdoor__close:focus-visible,
.kodza-trapdoor__link:focus-visible,
.kodza-trapdoor__socials a:focus-visible {
outline: 2px solid var(--kz-trapdoor-fg);
outline-offset: 4px;
}
/* Two lines on the button; under the page, the same two lines are crossed */
.kodza-trapdoor__lines,
.kodza-trapdoor__cross {
position: relative;
flex: none;
width: 14px;
height: 8px;
}
.kodza-trapdoor__lines::before,
.kodza-trapdoor__lines::after,
.kodza-trapdoor__cross::before,
.kodza-trapdoor__cross::after {
content: "";
position: absolute;
left: 0;
width: 100%;
height: 1.5px;
border-radius: 1px;
background: currentColor;
}
.kodza-trapdoor__lines::before,
.kodza-trapdoor__cross::before {
top: 0;
}
.kodza-trapdoor__lines::after,
.kodza-trapdoor__cross::after {
top: 6.5px;
}
.kodza-trapdoor__lines::after {
transform-origin: left center;
transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-trapdoor__toggle:hover .kodza-trapdoor__lines::after {
transform: scaleX(0.55);
}
.kodza-trapdoor__cross::before {
transform: translateY(3.25px) rotate(45deg);
}
.kodza-trapdoor__cross::after {
transform: translateY(-3.25px) rotate(-45deg);
}
/* The menu: fixed over the whole screen. While it is open it sits right under the page */
.kodza-trapdoor__panel {
position: fixed;
inset: 0;
z-index: 0;
display: grid;
grid-template-rows: auto 1fr;
box-sizing: border-box;
width: 100%;
height: 100%;
max-width: none;
max-height: none;
margin: 0;
padding: 0;
border: 0;
overflow: hidden auto;
overscroll-behavior: contain;
background: var(--kz-trapdoor-bg);
color: var(--kz-trapdoor-fg);
font: inherit;
font-size: 15px;
line-height: 1.4;
text-align: left;
container-type: size;
-webkit-font-smoothing: antialiased;
}
.kodza-trapdoor__panel[hidden] {
display: none;
}
.kodza-trapdoor__panel:focus {
outline: none;
}
.kodza-trapdoor__bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: var(--kz-trapdoor-top) var(--kz-trapdoor-side) 0;
}
.kodza-trapdoor__label,
.kodza-trapdoor__index,
.kodza-trapdoor__meta,
.kodza-trapdoor__caption,
.kodza-trapdoor__info {
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
font-weight: 400;
line-height: 1.4;
letter-spacing: 0;
color: var(--kz-trapdoor-muted);
}
.kodza-trapdoor__label {
margin: 0;
}
/* Links on the left, the image that follows them on the right, the small print below.
The bottom padding keeps clear of the page lying folded at the bottom of the screen */
.kodza-trapdoor__stage {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr) clamp(170px, 23cqw, 320px);
grid-template-rows: 1fr auto;
gap: clamp(12px, 3cqh, 24px) clamp(32px, 7cqw, 120px);
box-sizing: border-box;
padding: clamp(12px, 3cqh, 40px) var(--kz-trapdoor-side) calc(var(--kz-trapdoor-fold, 0px) + 20px);
}
.kodza-trapdoor__nav {
position: relative;
align-self: center;
display: flex;
flex-direction: column;
}
.kodza-trapdoor__link {
position: relative;
display: grid;
grid-template-columns: 3ch max-content minmax(0, 1fr);
align-items: end;
column-gap: clamp(12px, 2cqw, 28px);
padding: clamp(5px, 1.1cqh, 9px) 0 clamp(4px, 0.9cqh, 7px);
border-radius: 4px;
color: inherit;
text-decoration: none;
}
/* The row's hairline, drawn from the left as the row arrives */
.kodza-trapdoor__link::before {
content: "";
position: absolute;
inset: 0 0 auto;
height: 1px;
background: var(--kz-trapdoor-line);
transform-origin: left center;
}
.kodza-trapdoor__index {
align-self: start;
padding-top: 4px;
transition: color 0.3s ease;
}
/* The word rises from behind this mask (room below for descenders, on the right for the nudge) */
.kodza-trapdoor__mask {
display: block;
overflow: hidden;
padding: 0.08em 0.16em 0.26em 0;
margin: -0.08em -0.16em -0.26em 0;
font-size: var(--kz-trapdoor-size); /* so these em are the word's */
}
.kodza-trapdoor__word {
display: block;
font-size: var(--kz-trapdoor-size);
font-weight: 500;
line-height: 0.95;
letter-spacing: -0.045em;
white-space: nowrap;
transition: translate 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
}
/* The word keeps its width; the note takes what is left and wraps on a small phone */
.kodza-trapdoor__meta {
padding-bottom: 0.45em;
text-align: right;
text-wrap: balance;
}
/* Pointing at a link: the others step back, the image moves next to it */
.kodza-trapdoor__nav:hover .kodza-trapdoor__link:not(.is-active) .kodza-trapdoor__word,
.kodza-trapdoor__nav:has(:focus-visible) .kodza-trapdoor__link:not(.is-active) .kodza-trapdoor__word {
opacity: 0.4;
}
.kodza-trapdoor__nav:hover .kodza-trapdoor__link.is-active .kodza-trapdoor__word,
.kodza-trapdoor__nav:has(:focus-visible) .kodza-trapdoor__link.is-active .kodza-trapdoor__word {
translate: 0.1em 0;
}
.kodza-trapdoor__link.is-active .kodza-trapdoor__index {
color: var(--kz-trapdoor-fg);
}
.kodza-trapdoor__media {
position: relative;
}
.kodza-trapdoor__figure {
position: absolute;
top: 0;
right: 0;
width: min(100%, calc((100cqh - 220px) * 0.62));
margin: 0;
translate: 0 var(--kz-trapdoor-y, 0px);
transition: translate 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
.kodza-trapdoor__figure.is-placing {
transition: none;
}
.kodza-trapdoor__frame {
position: relative;
aspect-ratio: 4 / 5;
overflow: hidden;
border-radius: 14px;
background: var(--kz-trapdoor-line);
}
.kodza-trapdoor__image {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
max-width: 100%;
object-fit: cover;
visibility: hidden;
}
.kodza-trapdoor__image.is-shown {
visibility: visible;
}
/* One caption per image, stacked; the new one rolls in as the old one rolls out */
.kodza-trapdoor__caption {
display: grid;
margin: 12px 0 0;
overflow: hidden;
}
.kodza-trapdoor__caption span {
grid-area: 1 / 1;
transform: translateY(110%);
}
.kodza-trapdoor__info {
grid-column: 1 / -1;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 8px 24px;
}
.kodza-trapdoor__info p {
margin: 0;
}
.kodza-trapdoor__socials {
display: flex;
gap: 16px;
}
.kodza-trapdoor__socials a {
border-radius: 3px;
color: var(--kz-trapdoor-fg);
text-decoration: none;
}
.kodza-trapdoor__socials a:hover {
text-decoration: underline;
text-underline-offset: 3px;
}
/* Phones: one column, no image (nothing to point at), no keyboard hint */
@container (max-width: 720px) {
.kodza-trapdoor__stage {
--kz-trapdoor-size: clamp(30px, min(11.5cqw, calc(16cqh - 46px)), 60px);
grid-template-columns: minmax(0, 1fr);
}
.kodza-trapdoor__media {
display: none;
}
.kodza-trapdoor__hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-trapdoor__lines::after,
.kodza-trapdoor__link,
.kodza-trapdoor__index,
.kodza-trapdoor__word,
.kodza-trapdoor__figure {
transition-duration: 0.01ms !important;
}
}
/* Theming example — on a dark site, the menu turns to paper:
.dark-site .kodza-trapdoor {
--kz-trapdoor-bg: #f2f2f0;
--kz-trapdoor-fg: #0a0a0a;
--kz-trapdoor-muted: rgba(10, 10, 10, 0.62);
--kz-trapdoor-line: rgba(10, 10, 10, 0.14);
--kz-trapdoor-ink: #f2f2f0;
--kz-trapdoor-on-ink: #0a0a0a;
}
*/
/* kodza-guard 1f00a804f389 — 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-trapdoor__toggle):not(#_),
:where(.kodza-trapdoor__close):not(#_) {
outline: revert;
outline-offset: revert;
}
:where(.kodza-trapdoor__panel):not(#_) {
outline: revert;
}
:where(.kodza-trapdoor__link):not(#_) {
outline: revert;
outline-offset: revert;
transition-duration: revert;
}
:where(.kodza-trapdoor__socials a:where(:not([class*="kodza-"]))):not(#_) {
outline: revert;
outline-offset: revert;
text-underline-offset: revert;
}
:where(.kodza-trapdoor__hint):not(#_):where(:not([hidden])) {
display: revert;
}
:where(.kodza-trapdoor__hint):not(#_):where([hidden]) {
display: none;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-trapdoor:not(#_),
.kodza-trapdoor__lines:not(#_),
.kodza-trapdoor__bar:not(#_),
.kodza-trapdoor__cross:not(#_),
.kodza-trapdoor__index:not(#_),
.kodza-trapdoor__mask:not(#_),
.kodza-trapdoor__word:not(#_),
.kodza-trapdoor__meta:not(#_),
.kodza-trapdoor__media:not(#_),
.kodza-trapdoor__figure:not(#_),
.kodza-trapdoor__frame:not(#_),
.kodza-trapdoor__info:not(#_),
.kodza-trapdoor__caption span:where(:not([class*="kodza-"])):not(#_) {
box-sizing: revert;
}
.kodza-trapdoor__toggle:not(#_),
.kodza-trapdoor__close:not(#_) {
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
min-height: revert;
}
.kodza-trapdoor__panel:not(#_) {
box-shadow: revert;
outline-offset: revert;
}
.kodza-trapdoor__label:not(#_),
.kodza-trapdoor__caption:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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;
}
.kodza-trapdoor__nav:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: 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-trapdoor__link:not(#_) {
border: revert;
margin: revert;
list-style: revert;
box-sizing: revert;
float: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: 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-trapdoor__image:not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: 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;
}
.kodza-trapdoor__socials:not(#_),
.kodza-trapdoor__hint:not(#_),
.kodza-trapdoor__info p:where(:not([class*="kodza-"]):not(.kodza-trapdoor__info [class*="kodza-"] *)):not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: 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-trapdoor__socials a:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
padding: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-trapdoor__label:not(#_):where(:not([hidden])),
.kodza-trapdoor__info p:where(:not([class*="kodza-"]):not(.kodza-trapdoor__info [class*="kodza-"] *)):not(#_):where(:not([hidden])),
.kodza-trapdoor__socials a:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-trapdoor__label:not(#_):where([hidden]),
.kodza-trapdoor__info p:where(:not([class*="kodza-"]):not(.kodza-trapdoor__info [class*="kodza-"] *)):not(#_):where([hidden]),
.kodza-trapdoor__socials a:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
display: none;
}
.kodza-trapdoor__lines:not(#_)::before,
.kodza-trapdoor__lines:not(#_)::after,
.kodza-trapdoor__cross:not(#_)::before,
.kodza-trapdoor__cross:not(#_)::after,
.kodza-trapdoor__link:not(#_)::before {
box-sizing: revert;
}
/* 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-trapdoor__toggle:not(#_),
.kodza-trapdoor__close:not(#_) {
display: inline-flex;
align-items: center;
gap: 10px;
height: 40px;
margin: 0;
padding: 0 18px 0 16px;
border: 0;
border-radius: 999px;
font: inherit;
font-size: 15px;
font-weight: 500;
line-height: 1;
letter-spacing: -0.01em;
white-space: nowrap;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.kodza-trapdoor__toggle:not(#_) {
background: var(--kz-trapdoor-ink);
color: var(--kz-trapdoor-on-ink);
}
.kodza-trapdoor__close:not(#_) {
background: var(--kz-trapdoor-fg);
color: var(--kz-trapdoor-bg);
}
.kodza-trapdoor__toggle:focus-visible:not(#_) {
outline: 2px solid var(--kz-trapdoor-ink);
outline-offset: 3px;
}
.kodza-trapdoor__close:focus-visible:not(#_) {
outline: 2px solid var(--kz-trapdoor-fg);
outline-offset: 4px;
}
.kodza-trapdoor__link:focus-visible:not(#_),
.kodza-trapdoor__socials a:focus-visible:not(#_) {
outline: 2px solid var(--kz-trapdoor-fg);
outline-offset: 4px;
}
.kodza-trapdoor__panel:focus:not(#_) {
outline: none;
}
.kodza-trapdoor__label:not(#_),
.kodza-trapdoor__caption:not(#_) {
font-family: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
font-weight: 400;
line-height: 1.4;
letter-spacing: 0;
color: var(--kz-trapdoor-muted);
}
.kodza-trapdoor__label:not(#_) {
margin: 0;
}
.kodza-trapdoor__nav:not(#_) {
position: relative;
display: flex;
}
.kodza-trapdoor__link:not(#_) {
position: relative;
display: grid;
padding: clamp(5px, 1.1cqh, 9px) 0 clamp(4px, 0.9cqh, 7px);
border-radius: 4px;
color: inherit;
text-decoration: none;
}
.kodza-trapdoor__image:not(#_) {
position: absolute;
display: block;
max-width: 100%;
}
.kodza-trapdoor__caption:not(#_) {
display: grid;
margin: 12px 0 0;
}
.kodza-trapdoor__info p:not(#_) {
margin: 0;
}
.kodza-trapdoor__socials:not(#_) {
display: flex;
}
.kodza-trapdoor__socials a:not(#_) {
border-radius: 3px;
color: var(--kz-trapdoor-fg);
text-decoration: none;
}
.kodza-trapdoor__socials a:hover:not(#_) {
text-decoration: underline;
text-underline-offset: 3px;
}
@container (max-width: 720px) {
.kodza-trapdoor__hint:not(#_) {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-trapdoor__link: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 — Trapdoor Menu
// The page marked with data-trapdoor-page tips back on its bottom edge like a trapdoor and shows
// the menu underneath. Each link rises from its mask as the edge uncovers it, the image follows
// the link you point at, and closing plays the same timeline backwards, from wherever it is.
// The page only carries a transform while the menu is open: its fixed elements (a theme's
// header) ride along with it, and everything is put back once it is down again.
(() => {
const SELECTOR = '.kodza-trapdoor';
const motion = window.matchMedia('(prefers-reduced-motion: reduce)');
const RISE = 'cubic-bezier(0.22, 1, 0.36, 1)';
const SWING = 'cubic-bezier(0.65, 0, 0.35, 1)';
const BACK = 1.6; // closing replays the opening backwards, this much faster
// While open the panel leaves the menu (under the page, out of the content): it takes these along
const VARS = ['bg', 'fg', 'muted', 'line', 'top', 'side', 'size'];
const FOCUSABLE = 'a[href], button:not([disabled]), input, select, textarea, [tabindex]:not([tabindex="-1"])';
const tilted = new WeakMap(); // page → how to put it down at once (one menu tilts a page at a time)
const transparent = (color) => !color || color === 'transparent' || /^rgba\(.*,\s*0\)$/.test(color);
// [time, progress] pairs along a cubic-bezier(): when does the edge pass a given row?
const curve = (easing) => {
const n = (easing.match(/-?\d*\.?\d+/g) || []).map(Number);
const [x1, y1, x2, y2] = n.length === 4 ? n : [0.76, 0, 0.24, 1];
const at = (s, a, b) => 3 * (1 - s) * (1 - s) * s * a + 3 * (1 - s) * s * s * b + s * s * s;
return Array.from({ length: 101 }, (_, i) => [at(i / 100, x1, x2), at(i / 100, y1, y2)]);
};
// A transform makes the page the containing block of its fixed elements: they are found
// first, then moved back to where they were on screen (see `rideAlong`)
const fixedInside = (page) => {
const found = [];
const walker = document.createTreeWalker(page, NodeFilter.SHOW_ELEMENT, {
acceptNode: (el) => {
const style = getComputedStyle(el);
if (style.display === 'none') return NodeFilter.FILTER_REJECT;
if (style.position !== 'fixed') return NodeFilter.FILTER_SKIP;
found.push({ el, box: el.getBoundingClientRect(), shift: style.translate, inline: el.style.translate, attr: el.hasAttribute('style') });
return NodeFilter.FILTER_REJECT;
},
});
while (walker.nextNode()) {
// acceptNode collects them
}
return found;
};
const rideAlong = (fixed, k) => fixed.forEach((item) => {
const now = item.el.getBoundingClientRect();
const [x = 0, y = 0] = item.shift === 'none' ? [] : item.shift.split(' ').map(parseFloat);
item.el.style.translate = `${x + (item.box.left - now.left) / k}px ${y + (item.box.top - now.top) / k}px`;
});
const letGo = (fixed) => fixed.forEach(({ el, inline, attr }) => {
el.style.translate = inline;
if (!attr && !el.getAttribute('style')) el.removeAttribute('style');
});
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const toggle = root.querySelector('.kodza-trapdoor__toggle');
const panel = root.querySelector('.kodza-trapdoor__panel');
if (!toggle || !panel) return;
const one = (s) => panel.querySelector(s);
const all = (s) => [...panel.querySelectorAll(s)];
const closer = one('.kodza-trapdoor__close');
const cross = one('.kodza-trapdoor__cross');
const stage = one('.kodza-trapdoor__stage');
const nav = one('.kodza-trapdoor__nav');
const links = all('.kodza-trapdoor__link');
const media = one('.kodza-trapdoor__media');
const figure = one('.kodza-trapdoor__figure');
const frame = one('.kodza-trapdoor__frame');
const caption = one('.kodza-trapdoor__caption');
const images = all('.kodza-trapdoor__image');
const captions = all('.kodza-trapdoor__caption span');
const infos = all('.kodza-trapdoor__info > *');
const home = [panel.parentNode, panel.nextSibling];
const css = (name) => getComputedStyle(root).getPropertyValue(`--kz-trapdoor-${name}`).trim();
let state = 'closed'; // closed, opening, open, closing
let sequence = []; // the opening: animations on one clock, so it can run backwards
let session = null; // what only lives while the menu is open
let tilt = null; // the page being tipped, and what it looked like before
let reduced = false;
let active = -1;
let layer = 1;
let run = 0;
let then = null;
// The page: named on the menu (data-page="…"), or the marked wrapper around it, or else
// the wrapper of a WordPress theme (block themes, Astra, GeneratePress, Kadence, OceanWP,
// Blocksy, Divi…). Without one, the menu opens over the page, the same sequence minus the tilt
const findPage = () => {
let el = null;
try {
el = root.dataset.page ? document.querySelector(root.dataset.page) : null;
} catch {
el = null;
}
el = el || root.closest('[data-trapdoor-page]') || document.querySelector('[data-trapdoor-page]') || root.closest('.wp-site-blocks, #page, #outer-wrap, #main-container, #page-container');
if (!el || el === document.body || el === document.documentElement) return null;
// It has to fill the screen (below the WordPress admin bar): otherwise part of the site, a
// header outside it or the space under a short page, would be left out of the tilt
const r = el.getBoundingClientRect();
const bar = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--wp-admin--admin-bar--height')) || 0;
const { clientWidth: vw, clientHeight: vh } = document.documentElement;
return r.top <= bar + 1 && r.left <= 1 && r.right >= vw - 1 && r.bottom >= vh - 1 ? el : null;
};
// The colour under the page's content, so the menu never shows through it
const ground = (page) => {
const own = css('page');
if (own && own !== 'auto') return own;
for (let el = page.parentElement; el; el = el.parentElement) {
const color = getComputedStyle(el).backgroundColor;
if (!transparent(color)) return color;
}
return '#ffffff';
};
// Where the page is on screen, in its own pixels (a scaled parent changes nothing). Only
// the visible part tips: it is clipped to the screen, the hinge is the bottom of the screen
const measure = (page) => {
const r = page.getBoundingClientRect();
const k = page.offsetWidth ? r.width / page.offsetWidth : 1;
const top = Math.max(r.top, 0);
const bottom = Math.min(r.bottom, document.documentElement.clientHeight);
const left = Math.max(r.left, 0);
const right = Math.min(r.right, document.documentElement.clientWidth);
const h = Math.max(bottom - top, 1) / k;
const depth = h * 1.5;
const lift = h * 0.22; // the eye sits a little above the hinge
const rad = ((parseFloat(css('angle')) || 84) * Math.PI) / 180;
const hinge = (bottom - r.top) / k;
return {
k, bottom, depth, lift, rad, hinge,
origin: `${((left + right) / 2 - r.left) / k}px ${hinge - lift}px`,
inset: [top - r.top, r.right - right, left - r.left].map((n) => Math.max(n, 0) / k),
// Height of screen the page still covers once tipped by `phi`
cover: (phi) => (lift - ((lift - h * Math.cos(phi)) * depth) / (depth + h * Math.sin(phi))) * k,
};
};
const pose = (g, phi, round, light) => ({
transform: `perspective(${g.depth}px) translateY(${g.lift}px) rotateX(${phi}rad) translateY(${-g.lift}px)`,
clipPath: `inset(${g.clip} round ${round}px)`,
filter: `brightness(${light})`,
});
const swing = (g) => [pose(g, 0, 0, 1), pose(g, g.rad, 24, parseFloat(css('shade')) || 0.6)];
// A flex or grid page shares its height out among its children: for the ride their sizes
// are held as they are, so a shorter page box changes nothing inside
const hold = (page, style) => {
if (style.display.includes('grid')) {
page.style.gridTemplateRows = style.gridTemplateRows;
page.style.gridTemplateColumns = style.gridTemplateColumns;
} else if (style.display.includes('flex')) {
const column = style.flexDirection.startsWith('column');
tilt.held = [...page.children].map((el) => {
const own = getComputedStyle(el);
const item = { el, flex: el.style.flex, attr: el.hasAttribute('style') };
el.style.flex = `0 0 ${column ? own.height : own.width}`;
return item;
});
}
};
const release = () => {
tilt.held.forEach(({ el, flex, attr }) => {
el.style.flex = flex;
if (!attr && !el.getAttribute('style')) el.removeAttribute('style');
});
tilt.held = [];
Object.assign(tilt.page.style, tilt.cut);
};
// With the page untransformed: where it is, where its fixed elements are. Below the hinge
// the page would swing towards the eye and stretch the scroll area: its box ends at the
// hinge for the ride (the space it leaves is kept as margin). Checked on the spot: if that
// moves anything inside, even with the children held, the page is left as it was
const rig = () => {
const { page } = tilt;
letGo(tilt.fixed);
release();
const g = measure(page);
tilt.fixed = fixedInside(page);
const style = getComputedStyle(page);
const full = page.offsetHeight;
let end = full;
if (g.hinge < full) {
const edges = style.boxSizing === 'border-box' ? 0 : ['paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'].reduce((sum, side) => sum + parseFloat(style[side]), 0);
const margin = parseFloat(style.marginBottom) || 0;
const boxes = (els) => els.map((el) => el.getBoundingClientRect()).map((r) => [r.top, r.left, r.width, r.height]);
const kids = [...page.children];
const before = boxes(kids);
const cut = () => {
page.style.height = `${Math.max(g.hinge - edges, 0)}px`;
page.style.overflowY = 'clip';
page.style.marginBottom = `${margin + full - g.hinge}px`;
return boxes(kids).some((box, i) => box.some((n, j) => Math.abs(n - before[i][j]) > 0.5));
};
let moved = cut();
if (moved && /flex|grid/.test(style.display)) {
release();
hold(page, style);
moved = cut();
}
if (moved) release();
else end = g.hinge;
}
const [top, right, left] = g.inset;
g.clip = [top, right, Math.max(end - g.hinge, 0), left].map((n) => `${n}px`).join(' ');
page.style.transformOrigin = g.origin;
panel.style.setProperty('--kz-trapdoor-fold', `${Math.round(g.cover(g.rad))}px`);
return g;
};
// The image beside the link it belongs to, without leaving the column
const place = (instant) => {
const link = links[active];
if (!link || !figure || !media?.offsetHeight) return;
const centre = nav.offsetTop + link.offsetTop + link.offsetHeight / 2 - media.offsetTop;
const room = media.offsetHeight - figure.offsetHeight;
const y = Math.max(0, Math.min(room, centre - frame.offsetHeight / 2));
if (instant) figure.classList.add('is-placing');
figure.style.setProperty('--kz-trapdoor-y', `${Math.round(y)}px`);
if (instant) {
void figure.offsetWidth;
figure.classList.remove('is-placing');
}
};
// Pointing at a link: the image slides next to it and the new picture wipes in from the
// side it comes from, over the old one; the caption rolls the same way
const activate = (i, instant = false) => {
if (i === active || !links[i]) return;
const down = i > active;
const was = active;
active = i;
links.forEach((link, j) => link.classList.toggle('is-active', j === i));
place(instant);
const ms = instant || reduced ? 0 : 1;
const image = images[i];
if (image && image !== images[was]) {
image.classList.add('is-shown');
image.style.zIndex = String(++layer);
image.animate([
{ clipPath: down ? 'inset(100% 0% 0% 0%)' : 'inset(0% 0% 100% 0%)', scale: 1.18 },
{ clipPath: 'inset(0% 0% 0% 0%)', scale: 1 },
], { duration: 800 * ms, easing: SWING }).finished.then(() => {
if (images[active] === image) images.forEach((el) => el !== image && el.classList.remove('is-shown'));
}, () => {});
}
const next = captions[i];
if (next && next !== captions[was]) {
const from = down ? 110 : -110;
captions[was]?.animate([{ transform: `translateY(${-from}%)` }], { duration: 600 * ms, easing: RISE, fill: 'forwards' });
next.animate([{ transform: `translateY(${from}%)` }, { transform: 'translateY(0%)' }], { duration: 600 * ms, easing: RISE, fill: 'forwards' });
}
};
// The opening, as one timeline. Every animation gets an end delay that makes it as long as
// the longest, so running them all backwards is the exact reverse, even halfway through.
const build = (mode, g) => {
const steps = [];
const add = (el, frames, delay, duration, easing = RISE, extra = {}) => {
if (el) steps.push([el, frames, { delay, duration, easing, ...extra }]);
};
if (mode === 'reduced') {
add(panel, [{ opacity: 0 }, { opacity: 1 }], 0, 180, 'ease');
} else {
const time = (parseFloat(css('duration')) || 1.1) * 1000;
const ease = css('ease') || 'cubic-bezier(0.76, 0, 0.24, 1)';
// A row rises as the edge of the page goes past it (flat: once the panel is down)
let uncover = (i) => 260 + i * 70;
if (mode === 'tilt') {
add(tilt.page, swing(g), 0, time, ease);
const samples = curve(ease);
const rows = links.map((link) => link.getBoundingClientRect().bottom);
uncover = (i) => (samples.find(([, p]) => g.bottom - g.cover(g.rad * p) >= rows[i]) || [1])[0] * time;
} else {
add(panel, [{ clipPath: 'inset(0% 0% 100% 0%)' }, { clipPath: 'inset(0% 0% 0% 0%)' }], 0, 700, SWING);
}
add(stage, [{ scale: 0.96 }, { scale: 1 }], 0, time, ease);
add(cross, [{ transform: 'translateY(0px) rotate(0deg)' }, { transform: 'translateY(3.25px) rotate(45deg)' }], 200, 600, RISE, { pseudoElement: '::before' });
add(cross, [{ transform: 'translateY(0px) rotate(0deg)' }, { transform: 'translateY(-3.25px) rotate(-45deg)' }], 200, 600, RISE, { pseudoElement: '::after' });
let at = 50;
links.forEach((link, i) => {
at = Math.max(at + 70, uncover(i) - 160);
add(link, [{ transform: 'scaleX(0)' }, { transform: 'scaleX(1)' }], at - 60, 900, SWING, { pseudoElement: '::before' });
add(link.querySelector('.kodza-trapdoor__word'), [{ transform: 'translateY(140%)' }, { transform: 'translateY(0%)' }], at, 950);
link.querySelectorAll('.kodza-trapdoor__index, .kodza-trapdoor__meta').forEach((small) => {
add(small, [{ opacity: 0, transform: 'translateY(6px)' }, { opacity: 1, transform: 'translateY(0px)' }], at + 220, 600);
});
});
add(frame, [{ clipPath: 'inset(100% 0% 0% 0%)', scale: 1.08 }, { clipPath: 'inset(0% 0% 0% 0%)', scale: 1 }], at + 60, 900);
add(caption, [{ opacity: 0 }, { opacity: 1 }], at + 560, 500, 'ease');
infos.forEach((info, i) => {
add(info, [{ opacity: 0, transform: 'translateY(10px)' }, { opacity: 1, transform: 'translateY(0px)' }], at + 220 + i * 70, 650);
});
}
const total = Math.max(...steps.map(([, , o]) => o.delay + o.duration));
return steps.map(([el, frames, o]) => el.animate(frames, { ...o, fill: 'both', endDelay: total - o.delay - o.duration }));
};
const play = (forward) => {
const token = ++run;
sequence.forEach((animation) => {
animation.updatePlaybackRate(forward ? 1 : -BACK);
animation.play();
});
Promise.all(sequence.map((animation) => animation.finished)).then(() => {
if (token !== run) return;
if (forward) state = 'open';
else land();
}, () => {});
};
// Down again: the animations, the borrowed styles and the listeners go, the panel goes home
const land = () => {
run++;
sequence.forEach((animation) => animation.cancel());
panel.getAnimations({ subtree: true }).forEach((animation) => animation.cancel());
sequence = [];
session?.abort();
session = null;
if (tilt) {
const { page, origin, background, attr, layer } = tilt;
letGo(tilt.fixed);
release();
Object.assign(page.style, layer);
page.style.transformOrigin = origin;
page.style.backgroundColor = background;
if (!attr && !page.getAttribute('style')) page.removeAttribute('style');
if (tilted.get(page) === land) tilted.delete(page);
tilt = null;
}
try {
if (panel.popover && panel.matches(':popover-open')) panel.hidePopover();
} catch {
// no popover support: it was a plain fixed layer
}
panel.removeAttribute('popover');
panel.removeAttribute('style');
panel.hidden = true;
if (panel.parentNode !== home[0]) home[0].insertBefore(panel, home[1]?.parentNode === home[0] ? home[1] : null);
images.forEach((image) => {
image.classList.remove('is-shown');
image.style.removeProperty('z-index');
if (!image.getAttribute('style')) image.removeAttribute('style');
});
links.forEach((link) => link.classList.remove('is-active'));
figure?.style.removeProperty('--kz-trapdoor-y');
if (figure && !figure.getAttribute('style')) figure.removeAttribute('style');
active = -1;
state = 'closed';
const next = then;
then = null;
next?.();
};
// While open the page stays put: a wheel or a swipe only scrolls what scrolls in the menu
const scrollsInside = (target, x, y, dy) => {
for (let el = target; el instanceof Element && panel.contains(el); el = el.parentElement) {
const box = el.getBoundingClientRect();
if (x < box.left || x > box.right || y < box.top || y > box.bottom) continue;
if (!/(auto|scroll)/.test(getComputedStyle(el).overflowY) || el.scrollHeight <= el.clientHeight + 1) continue;
if (dy > 0 ? el.scrollTop + el.clientHeight < el.scrollHeight - 1 : el.scrollTop > 0) return true;
}
return false;
};
const keydown = (event) => {
if (state === 'closing' || event.defaultPrevented) return;
if (event.key === 'Escape') {
event.preventDefault();
shut();
return;
}
const current = document.activeElement;
if (event.key === 'Tab') {
const stops = all(FOCUSABLE).filter((el) => el.getClientRects().length);
const first = stops[0];
const last = stops[stops.length - 1];
const outside = !panel.contains(current) || current === panel;
if (outside || (event.shiftKey && current === first) || (!event.shiftKey && current === last)) {
event.preventDefault();
(event.shiftKey ? last : first)?.focus();
}
return;
}
const i = links.indexOf(current);
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
event.preventDefault();
const step = event.key === 'ArrowDown' ? 1 : -1;
links[i < 0 ? (step > 0 ? 0 : links.length - 1) : (i + step + links.length) % links.length]?.focus();
} else if (event.key === 'Home' || event.key === 'End') {
event.preventDefault();
links[event.key === 'Home' ? 0 : links.length - 1]?.focus();
} else if ([' ', 'PageUp', 'PageDown'].includes(event.key) && !current?.closest?.('button, input, select, textarea')) {
event.preventDefault();
}
};
const listen = (s) => {
let last = 0;
const at = [scrollX, scrollY];
document.addEventListener('wheel', (event) => {
if (!scrollsInside(event.target, event.clientX, event.clientY, event.deltaY)) event.preventDefault();
}, { passive: false, signal: s });
document.addEventListener('touchstart', (event) => (last = event.touches[0].clientY), { passive: true, signal: s });
document.addEventListener('touchmove', (event) => {
const touch = event.touches[0];
const dy = last - touch.clientY;
last = touch.clientY;
if (!scrollsInside(event.target, touch.clientX, touch.clientY, dy)) event.preventDefault();
}, { passive: false, signal: s });
document.addEventListener('keydown', keydown, { signal: s });
// A scrollbar dragged anyway: the page goes back to where it tipped from
window.addEventListener('scroll', () => {
if (scrollX !== at[0] || scrollY !== at[1]) window.scrollTo({ left: at[0], top: at[1], behavior: 'instant' });
}, { signal: s });
let queued = 0;
window.addEventListener('resize', () => {
if (queued) return;
queued = requestAnimationFrame(() => {
queued = 0;
if (s.aborted) return;
if (tilt) {
const effect = sequence[0].effect;
effect.setKeyframes([]);
const g = rig();
effect.setKeyframes(swing(g));
rideAlong(tilt.fixed, g.k);
}
place(true);
});
}, { signal: s });
s.addEventListener('abort', () => cancelAnimationFrame(queued));
// A click on the page lying at the bottom brings it back
tilt?.page.addEventListener('click', (event) => {
if (state === 'closing') return;
event.preventDefault();
event.stopPropagation();
shut();
}, { capture: true, signal: s });
};
const enter = (keyboard) => {
(keyboard ? links[active] || closer : panel)?.focus({ preventScroll: true });
};
const open = (keyboard) => {
if (state === 'opening' || state === 'open') return;
toggle.setAttribute('aria-expanded', 'true');
if (state === 'closing') {
state = 'opening';
then = null;
play(true);
enter(keyboard);
return;
}
reduced = motion.matches;
const page = reduced ? null : findPage();
let g = null;
if (page) {
tilted.get(page)?.();
const { transformOrigin, backgroundColor, height, overflowY, marginBottom, gridTemplateRows, gridTemplateColumns } = page.style;
tilt = { page, origin: transformOrigin, background: backgroundColor, attr: page.hasAttribute('style'), cut: { height, overflowY, marginBottom, gridTemplateRows, gridTemplateColumns }, fixed: [], held: [], layer: {} };
tilted.set(page, land);
g = rig();
const shown = getComputedStyle(page);
if (transparent(shown.backgroundColor)) page.style.backgroundColor = ground(page);
// Page over panel over the rest of the theme (a header, a sticky bar), under the admin bar
const { position, zIndex } = page.style;
tilt.layer = { position, zIndex };
const still = shown.position === 'static';
if (!still || ['top', 'right', 'bottom', 'left'].every((side) => shown[side] === 'auto')) {
if (still) page.style.position = 'relative';
page.style.zIndex = '99991';
panel.style.zIndex = '99990';
}
}
// The panel leaves the menu while open, so the styles of a theme's content (links,
// paragraphs) never reach it: right under the page, or at the end of the document
VARS.forEach((name) => panel.style.setProperty(`--kz-trapdoor-${name}`, css(name)));
panel.style.fontFamily = getComputedStyle(root).fontFamily;
if (page) page.before(panel);
else document.body.append(panel);
panel.hidden = false;
if (!page) {
try {
panel.popover = 'manual';
panel.showPopover();
} catch {
// no popover support: a fixed layer over the page
}
}
const current = links.findIndex((link) => link.getAttribute('aria-current'));
activate(Math.max(current, 0), true);
sequence = build(page ? 'tilt' : reduced ? 'reduced' : 'flat', g);
if (tilt) rideAlong(tilt.fixed, g.k);
session = new AbortController();
listen(session.signal);
state = 'opening';
play(true);
enter(keyboard);
};
const shut = (after) => {
if (state === 'closed' || state === 'closing') return;
then = after || null;
state = 'closing';
toggle.setAttribute('aria-expanded', 'false');
toggle.focus({ preventScroll: true });
play(false);
};
// Keyboard (Enter, Space) clicks have no detail: the focus then goes to the first link
toggle.addEventListener('click', (event) => open(event.detail === 0), { signal });
closer?.addEventListener('click', () => shut(), { signal });
links.forEach((link, i) => {
link.addEventListener('pointerenter', (event) => event.pointerType !== 'touch' && activate(i), { signal });
link.addEventListener('focus', () => activate(i), { signal });
// A link to this very page (#section, or just #) closes the menu first, then goes there
link.addEventListener('click', (event) => {
const here = link.origin === location.origin && link.pathname === location.pathname && link.search === location.search;
if (!here || event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
event.preventDefault();
const hash = link.hash;
shut(hash ? () => (location.hash = hash) : null);
}, { signal });
});
// Back from another page (bfcache): the menu is closed, the page flat
window.addEventListener('pageshow', (event) => event.persisted && state !== 'closed' && land(), { signal });
// Stopped while open: the page is put down at once and the panel goes back in place
signal.addEventListener('abort', () => {
then = null;
if (state !== 'closed') land();
});
}
// 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 — Trapdoor Menu, for React. From https://kodza.dev/components/trapdoor-menu/
// 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: trapdoor-menu.css and trapdoor-menu.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 './trapdoor-menu.css';
export type TrapdoorMenuProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** the menu, under the page — default: #0a0a0a */
"--kz-trapdoor-bg"?: string | number;
/** default: #f2f2f0 */
"--kz-trapdoor-fg"?: string | number;
/** default: rgba(242, 242, 240, 0.62) */
"--kz-trapdoor-muted"?: string | number;
/** default: rgba(242, 242, 240, 0.16) */
"--kz-trapdoor-line"?: string | number;
/** the Menu button, on the page — default: #0a0a0a */
"--kz-trapdoor-ink"?: string | number;
/** default: #ffffff */
"--kz-trapdoor-on-ink"?: string | number;
/** the page colour while it tips; auto = the first background above it — default: auto */
"--kz-trapdoor-page"?: string | number;
/** match your header, so Close lands right where Menu was (below the WordPress admin bar) — default: calc(var(--wp-admin--admin-bar--height, 0px) + 20px) */
"--kz-trapdoor-top"?: string | number;
/** default: 24px */
"--kz-trapdoor-side"?: string | number;
/** default: clamp(28px, min(7.4cqw, calc(16cqh - 46px)), 104px) */
"--kz-trapdoor-size"?: string | number;
/** how far the page tips back — default: 84deg */
"--kz-trapdoor-angle"?: string | number;
/** how dark it gets on the way down — default: 0.6 */
"--kz-trapdoor-shade"?: string | number;
/** default: 1.1s */
"--kz-trapdoor-duration"?: string | number;
/** default: cubic-bezier(0.76, 0, 0.24, 1) */
"--kz-trapdoor-ease"?: string | number;
};
className?: string;
};
export function TrapdoorMenu({ vars, className, style, ...rest }: TrapdoorMenuProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-trapdoor", 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('./trapdoor-menu.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 key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<button className="kodza-trapdoor__toggle" type="button" aria-haspopup="dialog" aria-expanded="false"><span className="kodza-trapdoor__lines" aria-hidden="true" />Menu</button>
<div className="kodza-trapdoor__panel" role="dialog" aria-modal="true" aria-label="Menu" tabIndex={-1} hidden>
<div className="kodza-trapdoor__bar">
<p className="kodza-trapdoor__label">5 doors, no stairs</p>
<button className="kodza-trapdoor__close" type="button"><span className="kodza-trapdoor__cross" aria-hidden="true" />Close</button>
</div>
<div className="kodza-trapdoor__stage">
<nav className="kodza-trapdoor__nav" aria-label="Main">
<a className="kodza-trapdoor__link" href="#">
<span className="kodza-trapdoor__index">01</span>
<span className="kodza-trapdoor__mask">
<span className="kodza-trapdoor__word">Work</span>
</span>
<span className="kodza-trapdoor__meta">12 shipped</span>
</a>
{' '}
<a className="kodza-trapdoor__link" href="#">
<span className="kodza-trapdoor__index">02</span>
<span className="kodza-trapdoor__mask">
<span className="kodza-trapdoor__word">Studio</span>
</span>
<span className="kodza-trapdoor__meta">est. 2019</span>
</a>
{' '}
<a className="kodza-trapdoor__link" href="#">
<span className="kodza-trapdoor__index">03</span>
<span className="kodza-trapdoor__mask">
<span className="kodza-trapdoor__word">Journal</span>
</span>
<span className="kodza-trapdoor__meta">weekly-ish</span>
</a>
{' '}
<a className="kodza-trapdoor__link" href="#">
<span className="kodza-trapdoor__index">04</span>
<span className="kodza-trapdoor__mask">
<span className="kodza-trapdoor__word">Lab</span>
</span>
<span className="kodza-trapdoor__meta">may break</span>
</a>
{' '}
<a className="kodza-trapdoor__link" href="#">
<span className="kodza-trapdoor__index">05</span>
<span className="kodza-trapdoor__mask">
<span className="kodza-trapdoor__word">Contact</span>
</span>
<span className="kodza-trapdoor__meta">replies in a day</span>
</a>
</nav>
<div className="kodza-trapdoor__media" aria-hidden="true">
<div className="kodza-trapdoor__figure">
<div className="kodza-trapdoor__frame">
<img className="kodza-trapdoor__image" src="https://kodza.dev/media/kz-columns-1400.webp" alt="" width="1120" height="1400" decoding="async" />
{' '}
<img className="kodza-trapdoor__image" src="https://kodza.dev/media/kz-block-1400.webp" alt="" width="1120" height="1400" decoding="async" />
{' '}
<img className="kodza-trapdoor__image" src="https://kodza.dev/media/kz-stack-1400.webp" alt="" width="1400" height="1050" decoding="async" />
{' '}
<img className="kodza-trapdoor__image" src="https://kodza.dev/media/kz-float-1400.webp" alt="" width="1400" height="933" decoding="async" />
{' '}
<img className="kodza-trapdoor__image" src="https://kodza.dev/media/kz-steps-1400.webp" alt="" width="1400" height="933" decoding="async" />
</div>
<p className="kodza-trapdoor__caption">
<span>display: grid</span>
<span>display: block</span>
<span>z-index: 9999</span>
<span>float: left</span>
<span>steps(5, end)</span>
</p>
</div>
</div>
<div className="kodza-trapdoor__info">
<p>Open for new work · Q1 2027</p>
<p className="kodza-trapdoor__socials">
<a href="#">GitHub</a>
<a href="#">X</a>
<a href="#">RSS</a>
</p>
<p className="kodza-trapdoor__hint">Esc puts the floor back.</p>
</div>
</div>
</div>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.