Add to Cart
Add-to-cart button that confirms with a tick while a copy of the product picture flies into the cart icon and its count rolls up by one. Rolls back if the request fails.
View codeThe cue at the bottom of a hero: an arrow in a ring or a mouse whose wheel rolls now and then. One click glides to the next section, the first scroll fades it out, and it comes back at the top.
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 Scroll Down to my page.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<button class="kodza-scroll-down" type="button" aria-label="Scroll to the next section">
<span class="kodza-scroll-down__icon" aria-hidden="true">
<svg viewBox="0 0 18 18"><path d="M9 2.75v12.5M4 10.25l5 5 5-5" /></svg>
</span>
</button>
<button class="kodza-scroll-down kodza-scroll-down--mouse" type="button" aria-label="Scroll to the next section">
<span class="kodza-scroll-down__icon" aria-hidden="true">
<span class="kodza-scroll-down__wheel"></span>
</span>
</button>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Scroll Down
The cue at the bottom of a hero: an arrow in a ring, or a mouse (--mouse) whose wheel rolls.
Now and then the glyph rolls down and a new one drops in from above; under the pointer, ink
pours in from the top. A click glides to the section after the hero (or data-target), the
first scroll fades it out, and it comes back at the top. data-hide="120" waits longer before
it steps aside, data-hide="never" keeps it.
Everything is tuned with the --kz-scroll-down-* variables. */
.kodza-scroll-down {
--kz-scroll-down-ink: #0a0a0a;
--kz-scroll-down-paper: #ffffff;
--kz-scroll-down-line: rgba(10, 10, 10, 0.28);
--kz-scroll-down-size: 52px;
--kz-scroll-down-travel: 36px;
--kz-scroll-down-ease: cubic-bezier(0.22, 1, 0.36, 1);
position: relative;
display: inline-grid;
place-items: center;
margin: 0;
padding: 0;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--kz-scroll-down-ink);
font: inherit;
line-height: 0;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
transition: opacity 0.5s var(--kz-scroll-down-ease), transform 0.5s var(--kz-scroll-down-ease), visibility 0s;
}
.kodza-scroll-down:focus-visible {
outline: 2px solid var(--kz-scroll-down-ink);
outline-offset: 4px;
}
/* Past the hero it steps aside, slowly, and leaves the Tab order once it is gone */
.kodza-scroll-down.is-away {
opacity: 0;
transform: translateY(12px);
visibility: hidden;
transition: opacity 0.6s cubic-bezier(0.65, 0, 0.35, 1), transform 0.6s cubic-bezier(0.65, 0, 0.35, 1), visibility 0s linear 0.6s;
}
.kodza-scroll-down__icon {
position: relative;
display: block;
width: var(--kz-scroll-down-size);
height: var(--kz-scroll-down-size);
border-radius: inherit;
transition: transform 0.25s var(--kz-scroll-down-ease);
}
.kodza-scroll-down:active .kodza-scroll-down__icon {
transform: scale(0.95);
}
.kodza-scroll-down__icon svg {
display: block;
width: 18px;
height: 18px;
overflow: visible;
fill: none;
stroke: currentColor;
stroke-width: 1.6;
stroke-linecap: round;
stroke-linejoin: round;
}
/* The mouse: a body with its wheel near the top */
.kodza-scroll-down--mouse {
--kz-scroll-down-travel: 14px;
border-radius: 14px;
}
.kodza-scroll-down--mouse .kodza-scroll-down__icon {
width: 28px;
height: 44px;
}
.kodza-scroll-down__wheel {
display: block;
width: 2px;
height: 7px;
margin-top: 2px;
border-radius: 1px;
background: currentColor;
}
/* Built by the script: the outline, and an ink copy on top that pours in from the top */
.kodza-scroll-down__layer {
position: absolute;
inset: 0;
overflow: hidden;
border-radius: inherit;
box-shadow: inset 0 0 0 1.5px var(--kz-scroll-down-line);
}
/* The mouse is a thinner shape than the ring: its outline takes more ink to read as clearly */
.kodza-scroll-down--mouse .kodza-scroll-down__layer:not(.kodza-scroll-down__layer--fill) {
box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--kz-scroll-down-ink) 50%, transparent);
}
.kodza-scroll-down__layer--fill {
background: var(--kz-scroll-down-ink);
color: var(--kz-scroll-down-paper);
box-shadow: none;
clip-path: inset(0 0 100% 0);
}
.kodza-scroll-down.is-in .kodza-scroll-down__layer--fill {
clip-path: inset(0);
transition: clip-path 0.45s cubic-bezier(0.65, 0, 0.35, 1);
}
/* On the way out it drains through the bottom, the way the arrow points */
.kodza-scroll-down.is-out .kodza-scroll-down__layer--fill {
clip-path: inset(100% 0 0 0);
transition: clip-path 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
/* The window the glyph rolls through: the whole ring, or a slit under the wheel */
.kodza-scroll-down__slot {
position: absolute;
inset: 0;
overflow: hidden;
}
.kodza-scroll-down--mouse .kodza-scroll-down__slot {
inset: 7px 11px auto;
height: 16px;
}
.kodza-scroll-down__track {
position: absolute;
inset: 0;
display: grid;
place-items: center;
}
.kodza-scroll-down--mouse .kodza-scroll-down__track {
align-items: start;
}
.kodza-scroll-down__track > * {
grid-area: 1 / 1;
}
/* The glyph waiting above, which drops into place as the first one leaves at the bottom */
.kodza-scroll-down__track > :last-child {
transform: translateY(calc(-1 * var(--kz-scroll-down-travel)));
}
.kodza-scroll-down.is-rolling .kodza-scroll-down__track {
animation: kodza-scroll-down-roll 0.85s cubic-bezier(0.65, 0, 0.35, 1);
}
@keyframes kodza-scroll-down-roll {
to {
transform: translateY(var(--kz-scroll-down-travel));
}
}
@media (prefers-reduced-motion: reduce) {
.kodza-scroll-down,
.kodza-scroll-down__icon,
.kodza-scroll-down__layer--fill {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
.kodza-scroll-down.is-rolling .kodza-scroll-down__track {
animation: none;
}
}
/* Theming example — on a dark background:
.dark-section .kodza-scroll-down {
--kz-scroll-down-ink: #ffffff;
--kz-scroll-down-paper: #0a0a0a;
--kz-scroll-down-line: rgba(255, 255, 255, 0.34);
}
*/
/* kodza-guard e1c2797e16cd — 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-scroll-down):not(#_) {
outline: revert;
outline-offset: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-scroll-down:not(#_) {
text-decoration: revert;
list-style: revert;
box-sizing: revert;
box-shadow: revert;
appearance: revert;
max-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
white-space: revert;
min-height: revert;
}
.kodza-scroll-down__icon:not(#_),
.kodza-scroll-down__layer:not(#_),
.kodza-scroll-down__slot:not(#_),
.kodza-scroll-down__track:not(#_),
.kodza-scroll-down__wheel:not(#_) {
box-sizing: revert;
}
.kodza-scroll-down__track svg:where(:not([class*="kodza-"])):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;
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;
}
/* 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-scroll-down:not(#_) {
position: relative;
display: inline-grid;
place-items: center;
margin: 0;
padding: 0;
border: 0;
border-radius: 999px;
background: transparent;
color: var(--kz-scroll-down-ink);
font: inherit;
line-height: 0;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
transition: opacity 0.5s var(--kz-scroll-down-ease), transform 0.5s var(--kz-scroll-down-ease), visibility 0s;
}
.kodza-scroll-down:focus-visible:not(#_) {
outline: 2px solid var(--kz-scroll-down-ink);
outline-offset: 4px;
}
.kodza-scroll-down.is-away:not(#_) {
opacity: 0;
transform: translateY(12px);
visibility: hidden;
transition: opacity 0.6s cubic-bezier(0.65, 0, 0.35, 1), transform 0.6s cubic-bezier(0.65, 0, 0.35, 1), visibility 0s linear 0.6s;
}
.kodza-scroll-down__icon svg:not(#_) {
display: block;
}
.kodza-scroll-down--mouse:not(#_) {
border-radius: 14px;
}
@media (prefers-reduced-motion: reduce) {
.kodza-scroll-down:not(#_) {
transition-duration: 0.01ms !important;
transition-delay: 0s !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Scroll Down
// The cue at the bottom of a hero. Now and then its glyph rolls down and a new one drops in
// from above; under the pointer, ink pours in. A click glides to the section after the hero
// (or data-target) and, from the keyboard, moves the focus there. The first scroll past the
// hero fades it out, and it comes back at the top.
(() => {
const SELECTOR = '.kodza-scroll-down';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const FIRST = 1400;
const EVERY = 3600;
// The box that scrolls it: the nearest scrolling ancestor, or the page (null)
const scrollerOf = (el) => {
for (let p = el.parentElement; p && p !== document.body && p !== document.documentElement; p = p.parentElement) {
const { overflowY } = getComputedStyle(p);
if ((overflowY === 'auto' || overflowY === 'scroll') && p.scrollHeight > p.clientHeight) return p;
}
return null;
};
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const icon = root.querySelector('.kodza-scroll-down__icon');
const glyph = icon?.firstElementChild;
if (!glyph) return;
// The outline and its ink copy, each with the glyph and its twin waiting above
const layer = (extra) => {
const el = document.createElement('span');
const slot = document.createElement('span');
const track = document.createElement('span');
el.className = `kodza-scroll-down__layer${extra}`;
slot.className = 'kodza-scroll-down__slot';
track.className = 'kodza-scroll-down__track';
track.append(glyph.cloneNode(true), glyph.cloneNode(true));
slot.append(track);
el.append(slot);
return el;
};
icon.replaceChildren(layer(''), layer(' kodza-scroll-down__layer--fill'));
const scroller = scrollerOf(root);
const scrollTop = () => (scroller ? scroller.scrollTop : window.scrollY);
const viewHeight = () => (scroller ? scroller.clientHeight : innerHeight);
const set = (y) => (scroller || window).scrollTo({ top: y, behavior: 'instant' });
// Where an element sits in the scrolled box, whatever scale the box is drawn at
const topOf = (el) => {
const r = el.getBoundingClientRect();
if (!scroller) return r.top + window.scrollY;
const box = scroller.getBoundingClientRect();
return (r.top - box.top) / (box.height / scroller.offsetHeight || 1) + scroller.scrollTop;
};
// The hero: the first block around it at least half a screen tall
const heroOf = () => {
for (let el = root.parentElement; el && el !== scroller && el !== document.body; el = el.parentElement) {
if (el.offsetHeight >= viewHeight() * 0.5) return el;
}
return null;
};
// The next section: data-target (or the link's #hash), else what follows the hero
const targetOf = () => {
const href = root.getAttribute('href');
const wanted = root.dataset.target || (href && href.length > 1 && href.startsWith('#') ? href : '');
if (wanted) {
try {
const found = document.querySelector(wanted);
if (found) return found;
} catch { /* not a selector: fall back to the next section */ }
}
for (let el = heroOf() || root.parentElement; el && el !== document.body; el = el.parentElement) {
for (let next = el.nextElementSibling; next; next = next.nextElementSibling) {
if (next.offsetHeight > 0) return next;
}
}
return null;
};
// The roll: both copies of the glyph move together, the twin lands where the glyph was
let rolling = false;
const roll = () => {
if (reduceMotion || rolling) return;
rolling = true;
root.classList.add('is-rolling');
};
root.addEventListener('animationend', (event) => {
if (event.animationName !== 'kodza-scroll-down-roll') return;
rolling = false;
root.classList.remove('is-rolling');
}, { signal });
// Now and then, only while it is shown and on screen
let away = false;
let inView = false;
let timer = 0;
const schedule = (wait = EVERY) => {
clearTimeout(timer);
if (reduceMotion || away || !inView) return;
timer = setTimeout(() => {
if (!document.hidden) roll();
schedule();
}, wait);
};
const seen = new IntersectionObserver(([entry]) => {
inView = entry.isIntersecting;
schedule(FIRST);
});
seen.observe(root);
// The ink: pours in under the pointer (or the keyboard focus), drains through the bottom
let hovered = false;
const sync = () => {
const want = !away && (hovered || root.matches(':focus-visible'));
const filled = root.classList.contains('is-in');
if (want && !filled) {
root.classList.remove('is-out');
root.classList.add('is-in');
roll();
schedule();
} else if (!want && filled) {
root.classList.remove('is-in');
root.classList.add('is-out');
}
};
const fill = icon.querySelector('.kodza-scroll-down__layer--fill');
fill.addEventListener('transitionend', (event) => {
if (event.propertyName === 'clip-path' && root.classList.contains('is-out')) root.classList.remove('is-out');
}, { signal });
root.addEventListener('pointerenter', (event) => {
if (event.pointerType === 'touch') return;
hovered = true;
sync();
}, { signal });
root.addEventListener('pointerleave', () => {
hovered = false;
sync();
}, { signal });
root.addEventListener('focus', sync, { signal });
root.addEventListener('blur', sync, { signal });
// Shown at rest, faded once the page has scrolled past the top of its hero
const limit = root.dataset.hide === 'never' ? Infinity : parseFloat(root.dataset.hide) || 40;
const update = () => {
const hero = heroOf();
let rest = hero ? topOf(hero) : 0;
if (rest < viewHeight() / 2) rest = 0;
const now = scrollTop() > rest + limit;
if (now === away) return;
away = now;
root.classList.toggle('is-away', away);
if (away) hovered = false;
sync();
schedule(FIRST);
};
// The glide: eased, and dropped as soon as the visitor scrolls or presses anything
let glide = null;
const stop = () => {
glide?.abort();
glide = null;
};
const glideTo = (y) => {
stop();
const box = scroller || document.documentElement;
const from = scrollTop();
const to = Math.max(0, Math.min(box.scrollHeight - (scroller ? scroller.clientHeight : innerHeight), y));
if (reduceMotion || Math.abs(to - from) < 2) {
set(to);
return;
}
const controller = new AbortController();
glide = controller;
const duration = Math.min(1400, 500 + Math.abs(to - from) * 0.45);
const start = performance.now();
const step = (now) => {
if (controller.signal.aborted) return;
const t = Math.min(1, (now - start) / duration);
set(from + (to - from) * (t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2));
if (t < 1) requestAnimationFrame(step);
else stop();
};
requestAnimationFrame(step);
['wheel', 'touchstart', 'pointerdown', 'keydown'].forEach((type) => {
window.addEventListener(type, stop, { passive: true, signal: controller.signal });
});
};
// From the keyboard the focus follows, on the section itself if nothing in it takes it
const focusOn = (el) => {
if (!el.matches('a[href], button, input, select, textarea, [tabindex]')) {
const outline = el.style.outline;
el.setAttribute('tabindex', '-1');
el.style.outline = 'none';
el.addEventListener('blur', () => {
el.removeAttribute('tabindex');
el.style.outline = outline;
}, { once: true, signal });
}
el.focus({ preventScroll: true });
};
root.addEventListener('click', (event) => {
const target = targetOf();
if (root.matches('a')) event.preventDefault();
if (!target) {
glideTo(scrollTop() + viewHeight());
return;
}
glideTo(topOf(target) - (parseFloat(getComputedStyle(target).scrollMarginTop) || 0));
if (event.detail === 0) focusOn(target);
}, { signal });
let ticking = false;
(scroller || window).addEventListener('scroll', () => {
if (ticking) return;
ticking = true;
requestAnimationFrame(() => {
ticking = false;
if (!signal.aborted) update();
});
}, { passive: true, signal });
window.addEventListener('resize', update, { signal });
signal.addEventListener('abort', () => {
stop();
clearTimeout(timer);
seen.disconnect();
});
update();
}
// 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.
const KODZA = Symbol.for('kodza');
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) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
const saved = { html: written(root), attrs: attrsOf(root), stop: () => destroy(root) };
instances.set(root, { controller, saved });
root[KODZA] = saved;
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);
// 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[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 — Scroll Down, for React. From https://kodza.dev/components/scroll-down/
// 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: scroll-down.css and scroll-down.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.
// 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 './scroll-down.css';
type Variant = "mouse";
export type ScrollDownProps = Omit<ComponentPropsWithoutRef<'button'>, "children" | "variant" | "vars"> & {
/** Modifier class(es): .kodza-scroll-down--mouse */
variant?: Variant | Variant[];
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-scroll-down-ink"?: string | number;
/** default: #ffffff */
"--kz-scroll-down-paper"?: string | number;
/** default: rgba(10, 10, 10, 0.28) */
"--kz-scroll-down-line"?: string | number;
/** default: 52px */
"--kz-scroll-down-size"?: string | number;
/** default: 36px */
"--kz-scroll-down-travel"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-scroll-down-ease"?: string | number;
};
className?: string;
};
export function ScrollDown({ variant, vars, className, style, ...rest }: ScrollDownProps) {
const ref = useRef<ComponentRef<'button'>>(null);
const classes = ["kodza-scroll-down", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-scroll-down--${v}`), 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('./scroll-down.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 (
<button type="button" aria-label="Scroll to the next section" key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<span className="kodza-scroll-down__icon" aria-hidden="true">
<svg viewBox="0 0 18 18">
<path d="M9 2.75v12.5M4 10.25l5 5 5-5" />
</svg>
</span>
</button>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.