Components84 / 118
Gallery Columns
A tilted wall of artworks in columns that loop forever, drifting and riding the page's scroll. Each column follows on its own spring so they lag and settle at different moments, and tiles stretch with speed. Hover lifts a tile toward you; click opens the artwork to fill the gallery with a springy overshoot.
GalleryGalleryMarqueeMarqueeParallaxParallaxFLIPFLIPSquash & stretchSquash & stretchGSAPGSAP
Drag or flick the wallClick an artwork to open it
Tweak
LIVELIVELook
-9°
Motion
26px/s
Usage
Follows your tweaks.
usage.tsx
import { GalleryColumns } from "@/components/inreact/gallery-columns";
const art = [
{ image: "/art/01.jpg", caption: "Opening March 15th", title: "Featured artists", href: "/artists" },
{ image: "/art/02.jpg", title: "Evening viewing" },
{ image: "/art/03.jpg" },
// ...
];
export function Gallery() {
return <GalleryColumns items={art} height={640} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/gallery-columns.jsonOr copy the source
Install the dependencies, then save this as components/inreact/gallery-columns.tsx.
terminal
npm install gsapcomponents/inreact/gallery-columns.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useLayoutEffect, useRef, useState, type PointerEvent as ReactPointerEvent } from "react";
/**
* Gallery Columns: a tilted wall of artworks in columns that drift past.
*
* Rounded artwork tiles in tilted columns that loop forever. They drift on
* their own and ride the page's scroll (and you can drag or flick them); each
* column follows on its own spring, so they lag, overshoot and settle at
* different moments, and the tiles stretch with speed. Point at a tile and it
* lifts and leans toward you. Click it and the artwork opens to fill the
* gallery with a springy overshoot while its caption resolves; click again
* (or Escape) and it folds back into its place.
*
* <GalleryColumns items={[{ image: "/art/1.jpg", title: "Evening viewing", caption: "Opening March 15th" }]} />
*/
export interface GalleryArt {
image: string;
/** Large serif line on the tile (optional). */
title?: string;
/** Small line above the title. */
caption?: string;
href?: string;
}
export interface GalleryColumnsProps {
items: GalleryArt[];
height?: number;
/** Columns (defaults to fit the width). */
columns?: number;
/** Degrees the wall is turned. */
tilt?: number;
/** Pixels per second the wall drifts by itself. */
drift?: number;
background?: string;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
const SERIF = `"Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif`;
export function GalleryColumns({ items, height = 560, columns, tilt = -9, drift = 26, background = "#050505", className }: GalleryColumnsProps) {
const rootRef = useRef<HTMLDivElement>(null);
const cols = useRef<(HTMLDivElement | null)[]>([]);
const overRef = useRef<HTMLDivElement>(null);
const [W, setW] = useState(0);
const [open, setOpen] = useState<GalleryArt | null>(null);
const n = items.length;
useEffect(() => {
const el = rootRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setW(e.contentRect.width));
ro.observe(el);
return () => ro.disconnect();
}, []);
const H = height;
// at least three columns, so even a small gallery reads as a wall
// tiles are sized by the height (and never wider than a third of the view);
// columns sit a tile apart, and there are as many as it takes to fill the
// tilted wall, which is wider than the view so its edges never show
const tile = Math.round(Math.min(H * 0.36, ((W * 1.28) / 3) * 0.8));
const colW = Math.round(tile * 1.2);
const C = columns ?? Math.max(3, Math.ceil((W * 1.3) / Math.max(1, colW)));
const span = C * colW;
const gapY = Math.round(tile * 0.2);
const per = Math.max(4, Math.ceil(((H * 1.6) / (tile + gapY)) ) + 1);
const loop = per * (tile + gapY);
// which artwork sits in each column slot (columns start at different points)
const pick = (c: number, i: number) => (c * 3 + i * (C + 1)) % Math.max(1, n);
useEffect(() => {
const root = rootRef.current;
if (!root || !W || !n) return;
const still = reduced();
const st = { y: 0, v: 0, drag: false };
// each column chases the wall on its own spring
const C_ = Array.from({ length: C }, (_, c) => ({ y: 0, v: 0, k: 70 + c * 22, z: 0.42 + (c % 2) * 0.08, speed: c % 2 ? 1.18 : 0.88 }));
const last = C_.map(() => "");
let lastScroll = window.scrollY;
const onScroll = () => {
const d = window.scrollY - lastScroll;
lastScroll = window.scrollY;
if (!still) st.v += clamp(-60, 60, d) * 3;
};
window.addEventListener("scroll", onScroll, { passive: true });
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (!st.drag) {
st.y += (st.v + (still ? 0 : drift)) * dt;
st.v *= Math.pow(0.04, dt);
}
const h = dt / 2;
C_.forEach((c, i) => {
const target = st.y * c.speed;
for (let s = 0; s < 2; s++) {
if (still) {
c.y = target;
c.v = 0;
break;
}
const cc = 2 * c.z * Math.sqrt(c.k);
c.v += (c.k * (target - c.y) - cc * c.v) * h;
c.y += c.v * h;
}
// tiles stretch with the column's speed
const sp = Math.abs(c.v);
const stretch = still ? 0 : Math.min(0.12, sp * 0.00011);
const off = -(((c.y % loop) + loop) % loop);
const tr = `translate3d(0,${off.toFixed(2)}px,0)`;
const key = `${tr}|${stretch.toFixed(3)}`;
if (key !== last[i]) {
const el = cols.current[i];
if (el) {
el.style.transform = tr;
el.style.setProperty("--st", (1 + stretch).toFixed(4));
}
last[i] = key;
}
});
};
gsap.ticker.add(tick);
// drag / flick (vertical)
let sy = 0, s0 = 0, ly = 0, lt = 0, moved = 0, id = -1, vv = 0;
const onDown = (e: PointerEvent) => {
if (e.button !== 0 || overRef.current?.contains(e.target as Node)) return;
id = e.pointerId;
st.drag = true;
sy = ly = e.clientY;
s0 = st.y;
lt = performance.now();
moved = 0;
vv = 0;
st.v = 0;
};
const onMove = (e: PointerEvent) => {
if (e.pointerId !== id || !st.drag) return;
const dy = e.clientY - sy;
moved = Math.max(moved, Math.abs(dy));
if (moved > 4 && !root.hasPointerCapture(e.pointerId)) {
try {
root.setPointerCapture(e.pointerId);
} catch {
/* capture is a nicety */
}
}
const now = performance.now();
vv = vv * 0.6 + (-(e.clientY - ly) / Math.max(1, now - lt)) * 1000 * 0.4;
ly = e.clientY;
lt = now;
st.y = s0 - dy;
};
const onUp = (e: PointerEvent) => {
if (e.pointerId !== id) return;
id = -1;
if (!st.drag) return;
st.drag = false;
st.v = moved > 5 ? clamp(-2400, 2400, vv) : 0;
if (moved <= 5) {
const t = (e.target as HTMLElement).closest<HTMLElement>("[data-art]");
if (t) openTile(t);
}
};
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerup", onUp);
root.addEventListener("pointercancel", onUp);
// open: the artwork grows from its tile to fill the gallery (FLIP), with a springy overshoot
let from: { x: number; y: number; w: number; h: number; r: number } | null = null;
let source: HTMLElement | null = null;
const openTile = (t: HTMLElement) => {
const art = items[Number(t.dataset.art)];
if (!art) return;
const rr = root.getBoundingClientRect();
const b = t.getBoundingClientRect(); // the rotated tile's box; use its centre and size
const size = tile;
from = { x: b.left + b.width / 2 - rr.left, y: b.top + b.height / 2 - rr.top, w: size, h: size, r: tilt };
source = t;
setOpen(art);
};
const close = () => {
const o = overRef.current;
if (!o || !from) return setOpen(null);
const cap = o.querySelectorAll("[data-cap]");
gsap.to(cap, { opacity: 0, y: 8, duration: 0.2, ease: "power2.in" });
gsap.to(o, {
x: from.x - W / 2,
y: from.y - H / 2,
width: from.w,
height: from.h,
rotation: from.r,
borderRadius: Math.round(tile * 0.12),
duration: still ? 0 : 0.55,
ease: "power3.inOut",
onComplete: () => {
if (source) source.style.visibility = "";
setOpen(null);
},
});
};
(root as HTMLDivElement & { __openEl?: (t: HTMLElement) => void; __close?: () => void }).__close = close;
(root as HTMLDivElement & { __openEl?: (t: HTMLElement) => void }).__openEl = openTile;
(root as HTMLDivElement & { __anim?: () => void }).__anim = () => {
const o = overRef.current;
if (!o || !from) return;
if (source) source.style.visibility = "hidden";
gsap.set(o, { left: W / 2, top: H / 2, xPercent: -50, yPercent: -50, x: from.x - W / 2, y: from.y - H / 2, width: from.w, height: from.h, rotation: from.r, borderRadius: Math.round(tile * 0.12) });
gsap.to(o, { x: 0, y: 0, width: W, height: H, rotation: 0, borderRadius: 0, duration: still ? 0 : 0.85, ease: "back.out(1.15)" });
const cap = o.querySelectorAll("[data-cap]");
gsap.fromTo(cap, { opacity: 0, y: 12, filter: "blur(6px)" }, { opacity: 1, y: 0, filter: "blur(0px)", duration: 0.6, stagger: 0.08, delay: still ? 0 : 0.45, ease: "power3.out" });
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") close();
};
window.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
window.removeEventListener("scroll", onScroll);
window.removeEventListener("keydown", onKey);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("pointercancel", onUp);
};
}, [W, H, C, n, items, loop, tile, tilt, drift]);
// when an artwork opens, run its FLIP (before paint, so it never flashes full-size)
useLayoutEffect(() => {
if (!open) return;
(rootRef.current as (HTMLDivElement & { __anim?: () => void }) | null)?.__anim?.();
}, [open]);
// hover: lift and lean toward the cursor
const onTileMove = (e: ReactPointerEvent<HTMLDivElement>) => {
const el = e.currentTarget, r = el.getBoundingClientRect();
const nx = (e.clientX - r.left) / r.width - 0.5, ny = (e.clientY - r.top) / r.height - 0.5;
gsap.to(el, { "--lift": 1, "--rx": -ny * 10, "--ry": nx * 12, duration: 0.4, ease: "power3.out", overwrite: true });
};
const onTileLeave = (e: ReactPointerEvent<HTMLDivElement>) => {
gsap.to(e.currentTarget, { "--lift": 0, "--rx": 0, "--ry": 0, duration: 0.7, ease: "elastic.out(1, 0.5)", overwrite: true });
};
return (
<div
ref={rootRef}
role="region"
aria-label="Gallery"
className={["relative w-full cursor-grab touch-pan-x overflow-hidden select-none active:cursor-grabbing", className].filter(Boolean).join(" ")}
style={{ height: H, background }}
>
{W > 0 && (
<div className="absolute top-1/2 left-1/2" style={{ width: span, height: H * 1.6, transform: `translate(-50%,-50%) rotate(${tilt}deg)` }}>
{Array.from({ length: C }, (_, c) => (
<div
key={c}
ref={(el) => void (cols.current[c] = el)}
className="absolute top-0 will-change-transform"
style={{ left: c * colW + (colW - tile) / 2, width: tile, paddingTop: c % 2 ? tile * 0.55 : 0 }}
>
{Array.from({ length: per * 2 }, (_, i) => {
const k = pick(c, i % per);
const art = items[k];
return (
<div
key={i}
data-art={k}
tabIndex={i < per ? 0 : -1}
role="button"
aria-label={art.title ?? "Artwork"}
onPointerMove={onTileMove}
onPointerLeave={onTileLeave}
onKeyDown={(e) => {
if (e.key === "Enter") (rootRef.current as (HTMLDivElement & { __openEl?: (t: HTMLElement) => void }) | null)?.__openEl?.(e.currentTarget);
}}
className="relative cursor-pointer outline-none [perspective:600px] focus-visible:[&>div]:ring-2 focus-visible:[&>div]:ring-white/60"
style={{ width: tile, height: tile, marginBottom: gapY }}
>
<div
className="relative h-full w-full overflow-hidden"
style={{
borderRadius: Math.round(tile * 0.12),
transform: "translateZ(calc(var(--lift, 0) * 30px)) rotateX(calc(var(--rx, 0) * 1deg)) rotateY(calc(var(--ry, 0) * 1deg)) scaleY(var(--st, 1))",
boxShadow: "0 10px 30px rgba(0,0,0,.45)",
}}
>
<img src={art.image} alt="" draggable={false} className="pointer-events-none h-full w-full object-cover" />
{(art.title || art.caption) && (
<div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center bg-black/10 p-3 text-center text-white [text-shadow:0_1px_10px_rgba(0,0,0,.45)]" style={{ fontFamily: SERIF }}>
{art.caption && <div style={{ fontSize: Math.max(7, tile * 0.07) }}>{art.caption}</div>}
{art.title && <div className="leading-[1.02] uppercase" style={{ fontSize: Math.max(9, tile * 0.11) }}>{art.title}</div>}
</div>
)}
</div>
</div>
);
})}
</div>
))}
</div>
)}
{/* the opened artwork */}
{open && (
<div
ref={overRef}
role="dialog"
aria-label={open.title ?? "Artwork"}
onClick={() => (rootRef.current as (HTMLDivElement & { __close?: () => void }) | null)?.__close?.()}
className="absolute z-20 cursor-zoom-out overflow-hidden"
style={{ left: 0, top: 0, width: W, height: H }}
>
<img src={open.image} alt={open.title ?? ""} draggable={false} className="pointer-events-none h-full w-full object-cover" />
<div className="absolute inset-0" style={{ background: "linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,.55) 100%)" }} />
<div className="absolute inset-x-6 bottom-7 text-white" style={{ fontFamily: SERIF }}>
{open.caption && (
<div data-cap className="text-[14px] opacity-0">
{open.caption}
</div>
)}
{open.title && (
<div data-cap className="mt-1 text-[clamp(26px,5vw,52px)] leading-none uppercase opacity-0">
{open.title}
</div>
)}
{open.href && (
<a data-cap href={open.href} onClick={(e) => e.stopPropagation()} className="mt-3 inline-block rounded-full bg-white px-4 py-2 font-sans text-[13px] text-black opacity-0">
View
</a>
)}
</div>
</div>
)}
</div>
);
}
export default GalleryColumns;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
7 propsitems{ image: string; title?: string; caption?: string; href?: string }[]The artworks.heightnumberHeight, px.default 560default 560columnsnumberColumns (defaults to fit the width).tiltnumberDegrees the wall is turned.default -9default -9driftnumberPixels per second it drifts by itself.default 26default 26backgroundstringBackground colour.default "#050505"default "#050505"classNamestringExtra classes.