Zoom Parallax
Zoom parallax scroll effect: a full-bleed hero shrinks into a seven-tile mosaic as surrounding tiles drift into place.
- Scroll & Hover Effects
- Travel
- React only · 0 deps
- 1 file
Browser support · All evergreen browsers (position: sticky, transforms). Reduced motion shows the settled mosaic.
Install. One command, or copy the file.
$
npx shadcn@latest add https://freedesignmd.com/r/zoom-parallax.json- Byte-identical to the preview
- No Tailwind or config needed
- SSR-safe · keyboard accessible
- Respects reduced motion & transparency
components/effects/zoom-parallax.tsx
1/**2 * ZoomParallax, Apple-style "zoom out" scroll scene. A full-bleed hero tile3 * starts filling the viewport; as you scroll, it shrinks into the centre of a4 * 7-tile mosaic while the six surrounding tiles scale and drift into place.5 * Text overlays fade out as the grid settles, a caption fades in.6 *7 * Props:8 * - tiles: exactly 7 ReactNodes; tiles[0] is the hero (centre) tile.9 * - overlay: ReactNode shown on the hero at the start (fades out).10 * - caption: ReactNode shown under the settled grid.11 * - length: scroll length in viewport heights (default 2.6).12 * - scrollContainer: optional ref; otherwise nearest scrollable ancestor.13 * CSS vars: --fd-zpx-bg, --fd-zpx-gap, --fd-zpx-radius.14 *15 * Layout: 4×3 mosaic on wide stages (hero spans 2×2), 2×4 under 640px.16 * Each tile's final rect is measured once per resize; per frame, only17 * transforms are written (FLIP-style inverse scale from the full-bleed rect).18 * Browser support: evergreen (sticky + transforms).19 * Demo images: /img/lux/{dunes,bamboo,lantern,still-vase,still-tea} and /img/halcyon/{positano-sunset,pool-lemons}.webp (+ -80020 * variants), included in the repo's public/img/lux, copy them next to your page or swap in your own.21 * Accessibility: tiles are aria-hidden art unless you pass labelled content;22 * overlay/caption text is real text. Reduced motion shows the settled grid.23 */24import { useEffect, useRef } from "react";25import type { CSSProperties, ReactNode, RefObject } from "react";26 27export interface ZoomParallaxProps {28 tiles: ReactNode[];29 overlay?: ReactNode;30 caption?: ReactNode;31 length?: number;32 scrollContainer?: RefObject<HTMLElement | null>;33 className?: string;34 style?: CSSProperties;35}36 37const clamp = (v: number, a = 0, b = 1) => (v < a ? a : v > b ? b : v);38const ease = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);39const easeOut = (t: number) => 1 - Math.pow(1 - t, 3);40 41function findScrollParent(el: HTMLElement): HTMLElement | null {42 let p = el.parentElement;43 while (p && p !== document.body && p !== document.documentElement) {44 const oy = getComputedStyle(p).overflowY;45 if ((oy === "auto" || oy === "scroll" || oy === "overlay") && p.scrollHeight > p.clientHeight + 1) return p;46 p = p.parentElement;47 }48 return null;49}50 51export function ZoomParallax({ tiles, overlay, caption, length = 2.6, scrollContainer, className, style }: ZoomParallaxProps) {52 const root = useRef<HTMLElement>(null);53 const stage = useRef<HTMLDivElement>(null);54 const cells = useRef<(HTMLDivElement | null)[]>([]);55 const inners = useRef<(HTMLDivElement | null)[]>([]);56 const ov = useRef<HTMLDivElement>(null);57 const cap = useRef<HTMLDivElement>(null);58 59 useEffect(() => {60 const el = root.current;61 const st = stage.current;62 if (!el || !st) return;63 if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {64 el.dataset.reduced = "";65 return;66 }67 const sc = scrollContainer?.current ?? findScrollParent(el);68 const target: HTMLElement | Window = sc ?? window;69 if (sc) el.dataset.contained = "";70 71 type Geo = { cx: number; cy: number; w: number; h: number };72 let geo: Geo[] = [];73 let S = { w: 0, h: 0 };74 let vh = 0;75 let raf = 0;76 let visible = true;77 let shown = -1;78 let lastT = 0;79 80 const measure = () => {81 vh = sc ? sc.clientHeight : window.innerHeight;82 if (sc) el.style.setProperty("--fd-zpx-vh", `${vh}px`);83 // read final layout with transforms cleared84 cells.current.forEach((c) => c && (c.style.transform = "none"));85 const sr = st.getBoundingClientRect();86 S = { w: sr.width, h: sr.height };87 geo = cells.current.map((c) => {88 if (!c) return { cx: 0, cy: 0, w: 1, h: 1 };89 const r = c.getBoundingClientRect();90 return { cx: r.left - sr.left + r.width / 2, cy: r.top - sr.top + r.height / 2, w: r.width, h: r.height };91 });92 };93 const progress = () => {94 const r = el.getBoundingClientRect();95 const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;96 const range = r.height - vh;97 return range > 0 ? clamp(-top / range) : 0;98 };99 const render = (p: number) => {100 // 0 → .78 : zoom out; .78 → 1 : hold101 const z = ease(clamp(p / 0.78));102 const hero = geo[0];103 if (!hero) return;104 // scale that makes the hero cover the stage105 const cover = Math.max(S.w / hero.w, S.h / hero.h);106 const k = cover + (1 - cover) * z; // current scale of the whole mosaic107 // the mosaic scales around the hero centre, which itself moves to stage centre at start108 const ox = (S.w / 2 - hero.cx) * (1 - z);109 const oy = (S.h / 2 - hero.cy) * (1 - z);110 for (let i = 0; i < geo.length; i++) {111 const c = cells.current[i];112 const g = geo[i];113 if (!c) continue;114 // per-tile stagger: outer tiles lag a bit and drift in (parallax)115 const dx = g.cx - hero.cx;116 const dy = g.cy - hero.cy;117 const lag = i === 0 ? 0 : 0.18 + 0.08 * ((i * 37) % 5) / 4;118 const zi = i === 0 ? z : easeOut(clamp((p / 0.78 - lag) / (1 - lag)));119 const ki = i === 0 ? k : cover * 1.25 + (1 - cover * 1.25) * zi;120 const tx = ox + dx * (k - 1) + dx * (ki - k) * 0.35;121 const ty = oy + dy * (k - 1) + dy * (ki - k) * 0.35;122 c.style.transform = `translate3d(${tx.toFixed(2)}px,${ty.toFixed(2)}px,0) scale(${(i === 0 ? k : ki).toFixed(4)})`;123 c.style.opacity = i === 0 ? "1" : clamp(zi * 1.6).toFixed(3);124 const inner = inners.current[i];125 // counter-scale content slightly so the hero art doesn't blow up linearly126 if (inner) inner.style.transform = `scale(${(1 + (i === 0 ? 0.18 : 0.3) * (1 - zi)).toFixed(4)})`;127 }128 if (ov.current) {129 const o = 1 - clamp(p / 0.28);130 ov.current.style.opacity = o.toFixed(3);131 ov.current.style.transform = `translate3d(0,${(-30 * (1 - o)).toFixed(2)}px,0)`;132 }133 if (cap.current) {134 const o = clamp((p - 0.7) / 0.2);135 cap.current.style.opacity = o.toFixed(3);136 cap.current.style.transform = `translate3d(0,${(16 * (1 - o)).toFixed(2)}px,0)`;137 }138 st.style.setProperty("--fd-zpx-r", `${(28 * (0.15 + 0.85 * z)).toFixed(2)}px`);139 };140 const tick = (t: number) => {141 const dt = Math.min(0.05, (t - lastT) / 1000 || 0.016);142 lastT = t;143 const goal = progress();144 if (shown < 0) shown = goal;145 shown += (goal - shown) * (1 - Math.exp(-dt * 12));146 if (Math.abs(goal - shown) < 0.0003) shown = goal;147 render(shown);148 raf = shown !== goal ? requestAnimationFrame(tick) : 0;149 };150 const kick = () => {151 if (!raf && visible) {152 lastT = performance.now();153 raf = requestAnimationFrame(tick);154 }155 };156 const onResize = () => {157 measure();158 render(shown < 0 ? progress() : shown);159 };160 measure();161 shown = progress();162 render(shown);163 const io = new IntersectionObserver(164 ([e]) => {165 visible = e.isIntersecting;166 if (visible) kick();167 },168 { root: sc ?? null },169 );170 io.observe(el);171 const ro = new ResizeObserver(onResize);172 ro.observe(st);173 target.addEventListener("scroll", kick, { passive: true });174 window.addEventListener("resize", onResize);175 return () => {176 io.disconnect();177 ro.disconnect();178 target.removeEventListener("scroll", kick);179 window.removeEventListener("resize", onResize);180 if (raf) cancelAnimationFrame(raf);181 };182 }, [scrollContainer, tiles.length]);183 184 return (185 <section ref={root} className={`fd-zpx${className ? " " + className : ""}`} style={{ ["--fd-zpx-len" as string]: String(length), ...style }}>186 <style>{css}</style>187 <div className="fd-zpx-pin">188 <div ref={stage} className="fd-zpx-stage">189 <div className="fd-zpx-grid">190 {tiles.slice(0, 7).map((t, i) => (191 <div192 key={i}193 ref={(n) => {194 cells.current[i] = n;195 }}196 className="fd-zpx-cell"197 data-i={i}198 >199 <div200 ref={(n) => {201 inners.current[i] = n;202 }}203 className="fd-zpx-inner"204 >205 {t}206 </div>207 </div>208 ))}209 </div>210 {overlay && (211 <div ref={ov} className="fd-zpx-overlay">212 {overlay}213 </div>214 )}215 {caption && (216 <div ref={cap} className="fd-zpx-caption">217 {caption}218 </div>219 )}220 </div>221 </div>222 </section>223 );224}225 226const css = `227.fd-zpx{228 --fd-zpx-bg:#F5F2EC;--fd-zpx-gap:12px;--fd-zpx-r:28px;229 position:relative;display:block;margin:0;padding:0;background:var(--fd-zpx-bg);230 height:calc(var(--fd-zpx-len) * 100vh);height:calc(var(--fd-zpx-len) * 100svh);231}232.fd-zpx,.fd-zpx *,.fd-zpx *::before,.fd-zpx *::after{box-sizing:border-box}233.fd-zpx[data-contained]{height:calc(var(--fd-zpx-len) * var(--fd-zpx-vh,100vh))}234.fd-zpx-pin{position:sticky;top:0;height:100vh;height:100svh;overflow:hidden;margin:0;padding:0}235.fd-zpx[data-contained] .fd-zpx-pin{height:var(--fd-zpx-vh,100vh)}236.fd-zpx-stage{position:relative;width:100%;height:100%;margin:0;padding:clamp(16px,4vh,40px) clamp(16px,3vw,40px) clamp(64px,12vh,112px)}237.fd-zpx-grid{238 display:grid;width:100%;height:100%;margin:0;padding:0;gap:var(--fd-zpx-gap);239 grid-template-columns:1fr 1.15fr 1.15fr 1fr;grid-template-rows:1fr 1fr 1fr;240 grid-template-areas:"a h h b" "c h h d" "e f f f";241}242.fd-zpx-cell{position:relative;min-width:0;min-height:0;overflow:hidden;border-radius:var(--fd-zpx-r);will-change:transform,opacity;transform-origin:50% 50%;background:#ddd}243.fd-zpx-cell[data-i="0"]{grid-area:h;z-index:2}244.fd-zpx-cell[data-i="1"]{grid-area:a}.fd-zpx-cell[data-i="2"]{grid-area:b}.fd-zpx-cell[data-i="3"]{grid-area:c}245.fd-zpx-cell[data-i="4"]{grid-area:d}.fd-zpx-cell[data-i="5"]{grid-area:e}.fd-zpx-cell[data-i="6"]{grid-area:f}246.fd-zpx-inner{position:absolute;inset:0;will-change:transform}247.fd-zpx-inner > *{display:block;width:100%;height:100%}248.fd-zpx-overlay{position:absolute;inset:0;z-index:5;isolation:isolate;display:flex;flex-direction:column;justify-content:flex-end;pointer-events:none;padding:clamp(24px,6vh,64px) clamp(20px,5vw,72px)}249.fd-zpx-caption{position:absolute;left:0;right:0;bottom:0;z-index:5;display:flex;align-items:center;justify-content:center;height:clamp(64px,12vh,112px);opacity:0;padding:0 16px}250@media (max-width:640px){251 .fd-zpx{--fd-zpx-gap:8px}252 .fd-zpx-grid{grid-template-columns:1fr 1fr;grid-template-rows:.8fr 1.3fr 1.3fr .8fr;grid-template-areas:"a b" "h h" "h h" "e f"}253 .fd-zpx-cell[data-i="3"],.fd-zpx-cell[data-i="4"]{display:none}254 .fd-zpx-cell[data-i="6"]{grid-area:f}255}256.fd-zpx[data-reduced]{height:auto}257.fd-zpx[data-reduced] .fd-zpx-pin{position:relative;height:100vh}258.fd-zpx[data-reduced] .fd-zpx-overlay{display:none}259.fd-zpx[data-reduced] .fd-zpx-caption{opacity:1}260`;261 262/* ------------------------------------------------------------------ Demo */263 264const TILES: { src: string; label: string; place: string; pos: string }[] = [265 { src: "../halcyon/positano-sunset", label: "Cliffside village of pastel houses above the sea at golden hour", place: "Positano", pos: "70% 50%" },266 { src: "dunes", label: "Wind-carved golden desert dunes under a violet dusk sky", place: "Wadi Rum", pos: "60% 50%" },267 { src: "bamboo", label: "Sunlight through a bamboo grove", place: "Arashiyama", pos: "50% 50%" },268 { src: "../halcyon/pool-lemons", label: "Lemon pergola and blue pool above the Amalfi coastline", place: "Ravello", pos: "65% 50%" },269 { src: "lantern", label: "Glowing paper lanterns against dark striped timber", place: "Gion, Kyoto", pos: "50% 45%" },270 { src: "still-vase", label: "White ceramic vase with an olive branch in an arch niche", place: "Tuscany", pos: "50% 60%" },271 { src: "still-tea", label: "Black teapot and two cups on a dark tray", place: "Fez", pos: "50% 60%" },272];273 274export function Demo() {275 return (276 <div className="fd-zpx-demo">277 <style>{demoCss}</style>278 <ZoomParallax279 tiles={TILES.map((t, i) => (280 <figure key={t.src} className="fd-zpx-demo-fig">281 <img src={`/img/lux/${t.src}${i === 0 ? "" : "-800"}.webp`} width={i === 0 || i === 1 || i === 3 ? 1920 : 1200} height={i === 0 || i === 1 || i === 3 ? 1200 : 1500} alt={t.label} loading={i === 0 ? "eager" : "lazy"} decoding="async" style={{ objectPosition: t.pos }} />282 <figcaption className="fd-zpx-demo-place">{t.place}</figcaption>283 </figure>284 ))}285 overlay={286 <div className="fd-zpx-demo-ov">287 <span className="fd-zpx-demo-brand">Wayfarer & Co.</span>288 <h1 className="fd-zpx-demo-h">289 Slow travel,290 <br />291 far from the crowds.292 </h1>293 <p className="fd-zpx-demo-cue" aria-hidden="true">294 <span className="fd-zpx-demo-cue-line" />295 Scroll296 </p>297 </div>298 }299 caption={300 <p className="fd-zpx-demo-cap">301 <strong>212 small-group journeys</strong> · 41 countries · guides who live there302 </p>303 }304 />305 <section className="fd-zpx-demo-after">306 <h2 className="fd-zpx-demo-h2">Autumn departures open 3 November.</h2>307 </section>308 </div>309 );310}311 312const demoCss = `313.fd-zpx-demo{display:block;margin:0;padding:0;background:#F5F2EC;color:#1A1714;min-height:100vh}314.fd-zpx-demo,.fd-zpx-demo *{box-sizing:border-box}315.fd-zpx-demo-fig{position:relative;display:block;width:100%;height:100%;margin:0;padding:0}316.fd-zpx-demo-fig img{display:block;width:100%;height:100%;max-width:none;margin:0;padding:0;object-fit:cover}317.fd-zpx-demo-place{position:absolute;left:12px;bottom:10px;margin:0;padding:5px 9px;border-radius:9999px;background:rgba(20,16,12,.38);color:#fff;318 font:500 0.6875rem/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,monospace;letter-spacing:.03em;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}319.fd-zpx-overlay::before{content:"";position:absolute;inset:0;z-index:-1;background:linear-gradient(to top,rgba(24,14,10,.55),rgba(24,14,10,0) 55%),linear-gradient(to bottom,rgba(24,14,10,.25),rgba(24,14,10,0) 20%)}320.fd-zpx-demo-ov{display:flex;flex-direction:column;height:100%;color:#fff;text-shadow:0 2px 30px rgba(40,14,8,.35)}321.fd-zpx-demo-brand{display:block;margin:0 0 auto;color:#fff;font:600 1.0625rem/1 ui-sans-serif,-apple-system,"Inter",sans-serif;letter-spacing:-0.01em}322.fd-zpx-demo-h{margin:0;padding:0;color:#fff;font:600 clamp(2.75rem,8vw,6.5rem)/.92 "SF Pro Display",ui-sans-serif,-apple-system,"Inter Display","Inter",sans-serif;letter-spacing:-0.05em}323.fd-zpx-demo-cue{display:inline-flex;align-items:center;gap:10px;margin:24px 0 0;padding:0;color:rgba(255,255,255,.85);font:500 0.75rem/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,monospace;letter-spacing:.08em;text-transform:uppercase}324.fd-zpx-demo-cue-line{position:relative;display:block;width:1px;height:28px;overflow:hidden;background:rgba(255,255,255,.3)}325.fd-zpx-demo-cue-line::after{content:"";position:absolute;left:0;top:0;width:1px;height:12px;background:#fff;animation:fd-zpx-cue 1.6s cubic-bezier(0.65,0,0.35,1) infinite}326@keyframes fd-zpx-cue{0%{transform:translateY(-12px)}100%{transform:translateY(28px)}}327.fd-zpx-demo-cap{margin:0;padding:0;color:#5E564C;text-align:center;font:400 0.9375rem/1.4 ui-sans-serif,-apple-system,"Inter",sans-serif}328.fd-zpx-demo-cap strong{color:#1A1714;font-weight:600}329.fd-zpx-demo-after{max-width:1200px;margin:0 auto;padding:96px clamp(16px,4vw,48px) 140px;text-align:center}330.fd-zpx-demo-h2{margin:0;padding:0;color:#1A1714;font:600 clamp(1.75rem,4vw,3rem)/1.05 "SF Pro Display",ui-sans-serif,-apple-system,"Inter Display","Inter",sans-serif;letter-spacing:-0.035em}331@media (prefers-reduced-motion: reduce){.fd-zpx-demo-cue-line::after{animation:none}}332`;More Scroll & Hover Effects. Same file contract.
Questions about Zoom Parallax
Run npx shadcn@latest add https://freedesignmd.com/r/zoom-parallax.json, or open the page and copy the file into your project. It has zero dependencies besides React. What you copy is the exact file that renders the live demo.
Zoom parallax scroll effect: a full-bleed hero shrinks into a seven-tile mosaic as surrounding tiles drift into place. It is a free, MIT-licensed React scroll & hover effects component from the freedesignmd library.
Yes. It is free and MIT-licensed, use, modify and ship it in personal and commercial projects without attribution.
All evergreen browsers (position: sticky, transforms). Reduced motion shows the settled mosaic.
Yes. It is a plain React component with its own styles, so it runs in Next.js, Vite, Remix and Lovable projects, and it needs no Tailwind setup. It has zero dependencies besides React.


