Components87 / 118
Pinch Strip
An endless strip of product photos sliding through a soft lens: in the bulge the band swells and the photo there stands large, toward the sides it pinches thin and the photos narrow into bow-tie shapes. The bulge follows your cursor, a drag or flick slides the strip, and a click glides a photo into the bulge.
CarouselCarouselProductsProductsWebGLWebGLLensLensDragDragSpringsSpringsSquash & stretchSquash & stretchthree.jsthree.jsGSAPGSAP
Drag to slide the stripClick a photo to bring it into the bulge
Tweak
LIVELIVEMotion
0.18 photos/s
Look
0.40
Usage
Follows your tweaks.
usage.tsx
import { PinchStrip } from "@/components/inreact/pinch-strip";
const products = [
{ src: "/shop/serum.jpg", title: "Serum 30ml", href: "/p/serum" },
{ src: "/shop/soap.jpg", title: "Bar soap", href: "/p/soap" },
// ...
];
export function Collection() {
return <PinchStrip items={products} height={420} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/pinch-strip.jsonOr copy the source
Install the dependencies, then save this as components/inreact/pinch-strip.tsx.
terminal
npm install gsap threecomponents/inreact/pinch-strip.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useRef, useState } from "react";
/**
* Pinch Strip: a band of photos that swells and pinches as it slides.
*
* An endless strip of rounded photos runs sideways through a soft lens: in
* the bulge the band swells and the photo there stands large; toward the
* sides it pinches thin, the photos narrowing into bow-tie shapes, their
* edges following the curve of the band. The bulge follows your cursor on a
* spring and swells a little more while you're over it. Drag or flick to
* slide (the band flattens with the speed and wobbles back), click a photo
* to glide it into the bulge (click it again to open its link). Arrow keys
* step, Enter opens. One WebGL pass (three) + GSAP's ticker.
*
* <PinchStrip items={[{ src: "/shop/1.jpg", title: "Serum 30ml", href: "/p/serum" }, ...]} />
*/
export interface PinchItem {
src: string;
title?: string;
href?: string;
}
export interface PinchStripProps {
items: PinchItem[];
height?: number;
/** How thin the band pinches (0 closes it, 1 is flat). */
pinch?: number;
/** Slide speed, photos per second (negative slides the other way). */
speed?: 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 ASPECT = 1.06; // photo width / height in the bulge
const PERIOD = 1.75; // bulge-to-bulge, in photo widths
const AT_W = 300, AT_H = 284; // atlas cell, px
const VERT = /* glsl */ `
varying vec2 vUv;
void main() { vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`;
const FRAG = /* glsl */ `
precision highp float;
varying vec2 vUv;
uniform sampler2D uAtlas;
uniform vec2 uAtlasGrid;
uniform float uCount;
uniform vec2 uRes; // px
uniform float uCx; // bulge centre, px from the middle
uniform float uOff; // slide, photos
uniform float uHmax; // band height in the bulge, px
uniform float uP; // bulge period, px
uniform float uMin; // pinch, fraction of uHmax
uniform float uMinW; // photo width at the pinch, fraction
uniform float uFper; // integral of 1/w over one period (in kx)
uniform vec3 uBg;
uniform float uGap; // px (bulge scale)
uniform float uRad;
const float TAU = 6.28318530718;
void main() {
vec2 s = (vUv - 0.5) * uRes;
float dx = s.x - uCx;
// band height: full in the bulge, pinched between bulges
float c = 0.5 + 0.5 * cos(TAU * dx / uP);
float g = 1.0 - (1.0 - c) * (1.0 - c) * (1.0 - c); // tall across the bulge photo, edges bowing gently
float h = uHmax * (uMin + (1.0 - uMin) * g);
// photo width: full across the bulge, then a sharp shoulder down to slivers at the pinch.
// slide coordinate = integral of 1 / w (Simpson), unwrapped period by period
float k = TAU / uP;
float kx = k * dx;
float np = floor((kx + 3.14159265) / TAU);
float r = kx - np * TAU;
float I = 0.0;
for (int i = 0; i <= 24; i++) {
float t = r * float(i) / 24.0;
float cc = 0.5 + 0.5 * cos(t);
float f = 1.0 / (uMinW + (1.0 - uMinW) * smoothstep(0.08, 0.5, cc));
I += f * (i == 0 || i == 24 ? 1.0 : (mod(float(i), 2.0) == 1.0 ? 4.0 : 2.0));
}
I *= r / 72.0;
float F = (I + np * uFper) / k;
float cw = 0.5 + 0.5 * cos(kx);
float w = uMinW + (1.0 - uMinW) * smoothstep(0.08, 0.5, cw);
float tw = uHmax * ${ASPECT.toFixed(2)};
float u = F / tw + uOff;
float id = floor(u);
// local photo coordinates at bulge scale, then the shape in screen px (gaps and corners stay even)
float lx = (fract(u) - 0.5) * tw;
float ly = s.y / h * uHmax;
vec2 scr = vec2(lx * w, s.y);
vec2 hs = vec2(tw * w, h) * 0.5 - uGap * 0.5;
float rad = min(uRad, min(hs.x, hs.y) * 0.9);
vec2 q = abs(scr) - (hs - rad);
float sd = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - rad;
float px = max(fwidth(u) * tw * w, fwidth(s.y)) * 0.85;
float al = 1.0 - smoothstep(-px, px, sd);
float pick = mod(id, uCount);
vec2 at = vec2(mod(pick, uAtlasGrid.x), floor(pick / uAtlasGrid.x));
vec2 inner = clamp(vec2(lx / tw, ly / uHmax) + 0.5, 0.0, 1.0);
vec2 uv = (at + vec2(inner.x, 1.0 - inner.y)) / uAtlasGrid;
uv.y = 1.0 - uv.y;
vec3 col = texture2D(uAtlas, uv).rgb;
gl_FragColor = vec4(mix(uBg, col, al), 1.0);
}`;
type Spring = { x: number; v: number; t: number };
const step = (b: Spring, k: number, c: number, h: number) => {
for (let i = 0; i < 2; i++) (b.v += (k * (b.t - b.x) - c * b.v) * (h / 2)), (b.x += b.v * (h / 2));
};
export function PinchStrip({ items, height = 420, pinch = 0.4, speed = 0.18, background = "#000000", className }: PinchStripProps) {
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const [W, setW] = useState(0);
const [front, setFront] = useState(0);
const n = items.length;
useEffect(() => {
const el = rootRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setW(Math.round(e.contentRect.width)));
ro.observe(el);
return () => ro.disconnect();
}, []);
useEffect(() => {
const host = hostRef.current, root = rootRef.current;
if (!host || !root || !W || !n) return;
const still = reduced();
const H = height;
const cols = Math.min(6, Math.ceil(Math.sqrt(n))), rows = Math.ceil(n / cols);
const atlas = document.createElement("canvas");
atlas.width = cols * AT_W;
atlas.height = rows * AT_H;
const actx = atlas.getContext("2d")!;
actx.fillStyle = "#1c1c1e";
actx.fillRect(0, 0, atlas.width, atlas.height);
const tex = new THREE.CanvasTexture(atlas);
tex.colorSpace = THREE.SRGBColorSpace;
tex.minFilter = THREE.LinearMipmapLinearFilter;
tex.anisotropy = 8;
items.forEach((p, i) => {
const im = new Image();
im.crossOrigin = "anonymous";
im.onload = () => {
const x = (i % cols) * AT_W, y = Math.floor(i / cols) * AT_H;
const z = Math.max(AT_W / im.naturalWidth, AT_H / im.naturalHeight);
const w = im.naturalWidth * z, h = im.naturalHeight * z;
actx.save();
actx.beginPath();
actx.rect(x, y, AT_W, AT_H);
actx.clip();
actx.drawImage(im, x + (AT_W - w) / 2, y + (AT_H - h) / 2, w, h);
actx.restore();
tex.needsUpdate = true;
};
im.src = p.src;
});
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;";
host.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: false });
} catch {
canvas.remove();
return;
}
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
renderer.setSize(W, H, false);
// the bulge: as tall as fits, never wider than ~45% of the width
const HMAX = Math.min(H * 0.6, W / (ASPECT * PERIOD));
const P = HMAX * ASPECT * PERIOD;
const TW = HMAX * ASPECT;
const bg = new THREE.Color(background);
const mat = new THREE.ShaderMaterial({
vertexShader: VERT,
fragmentShader: FRAG,
depthTest: false,
uniforms: {
uAtlas: { value: tex },
uAtlasGrid: { value: new THREE.Vector2(cols, rows) },
uCount: { value: n },
uRes: { value: new THREE.Vector2(W, H) },
uCx: { value: 0 },
uOff: { value: 0 },
uHmax: { value: HMAX },
uP: { value: P },
uMin: { value: pinch },
uMinW: { value: 0.13 },
uFper: { value: 1 },
uBg: { value: new THREE.Vector3(bg.r, bg.g, bg.b) },
uGap: { value: Math.max(6, HMAX * 0.05) },
uRad: { value: Math.max(6, HMAX * 0.075) },
},
});
const scene = new THREE.Scene();
const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), mat);
scene.add(quad);
const camera = new THREE.Camera();
const u = mat.uniforms;
const strip = { off: 0, v: 0, drag: false, lo: 0, tween: false };
const cx: Spring = { x: 0, v: 0, t: 0 }; // bulge centre, px from the middle
const swell: Spring = { x: 1, v: 0, t: 1 }; // bulge size while hovered
const sq: Spring = { x: 0, v: 0, t: 0 }; // flatten with speed
let lastFront = -1;
const fmod = (a: number, b: number) => a - b * Math.floor(a / b);
const MINW = 0.13;
const sstep = (a: number, b: number, x: number) => {
const t = clamp(0, 1, (x - a) / (b - a));
return t * t * (3 - 2 * t);
};
const invW = (t: number) => {
const c = 0.5 + 0.5 * Math.cos(t);
return 1 / (MINW + (1 - MINW) * sstep(0.08, 0.5, c));
};
const simpson = (r: number) => {
let I = 0;
for (let i = 0; i <= 24; i++) I += invW((r * i) / 24) * (i === 0 || i === 24 ? 1 : i % 2 ? 4 : 2);
return (I * r) / 72;
};
const FPER = 2 * simpson(Math.PI);
u.uMinW.value = MINW;
u.uFper.value = FPER;
// mirrors the shader: slide coordinate under a screen x (px from the middle)
const uAt = (x: number) => {
const hm = u.uHmax.value as number, p = u.uP.value as number;
const k = (Math.PI * 2) / p, kx = k * (x - cx.x);
const np = Math.floor((kx + Math.PI) / (Math.PI * 2)), r = kx - np * Math.PI * 2;
const F = (simpson(r) + np * FPER) / k;
return F / (hm * ASPECT) + strip.off;
};
const heightAt = (x: number) => {
const hm = u.uHmax.value as number, mn = u.uMin.value as number, p = u.uP.value as number;
const c = 0.5 + 0.5 * Math.cos((Math.PI * 2 * (x - cx.x)) / p);
return hm * (mn + (1 - mn) * (1 - (1 - c) ** 3));
};
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (!strip.drag && !strip.tween) {
const target = still ? 0 : speed;
strip.v = target + (strip.v - target) * Math.pow(0.1, dt);
strip.off += strip.v * dt;
}
const vel = (strip.off - strip.lo) / Math.max(dt, 1e-3);
strip.lo = strip.off;
if (still) (cx.x = cx.t), (swell.x = swell.t), (sq.x = 0);
else {
sq.t = clamp(0, 1, (Math.abs(vel) - 0.6) * 0.28);
step(cx, 60, 10.5, dt);
step(swell, 170, 9, dt);
step(sq, 150, 7, dt); // wobbles through zero as it settles
}
// squash and stretch: faster = flatter and longer bulges
const s = clamp(-0.5, 1, sq.x);
u.uHmax.value = (HMAX * swell.x) / (1 + 0.18 * s);
u.uP.value = P * swell.x * (1 + 0.22 * s);
u.uCx.value = cx.x;
u.uOff.value = strip.off;
renderer.render(scene, camera);
const f = fmod(Math.floor(uAt(cx.x)), n);
if (f !== lastFront) {
lastFront = f;
setFront(f);
}
};
gsap.ticker.add(tick);
// glide a photo (unwrapped id) into the bulge
const toBulge = (id: number) => {
strip.tween = true;
strip.v = 0;
const target = id + 0.5 - (uAt(cx.x) - strip.off);
gsap.to(strip, { off: target, duration: still ? 0 : 0.8, ease: "back.out(1.4)", overwrite: true, onComplete: () => void (strip.tween = false) });
};
let sx = 0, so = 0, moved = 0, pid = -1, lx = 0, lt = 0;
const local = (e: PointerEvent) => {
const r = root.getBoundingClientRect();
return { x: e.clientX - r.left - W / 2, y: e.clientY - r.top - H / 2 };
};
const onEnter = () => void (swell.t = 1.1);
const onMove = (e: PointerEvent) => {
const p = local(e);
cx.t = clamp(-W / 2, W / 2, p.x);
swell.t = 1.1;
if (strip.drag && e.pointerId === pid) {
const dx = e.clientX - sx;
moved = Math.max(moved, Math.abs(dx));
if (moved > 4) {
try {
if (!root.hasPointerCapture(e.pointerId)) root.setPointerCapture(e.pointerId);
} catch {
/* capture is a nicety */
}
}
const per = 1 / TW; // one photo per bulge-photo width dragged
strip.off = so - dx * per;
const now = performance.now(), ddt = Math.max(1, now - lt) / 1000;
strip.v = strip.v * 0.5 + ((-(e.clientX - lx) * per) / ddt) * 0.5;
lx = e.clientX;
lt = now;
return;
}
const onPhoto = Math.abs(p.y) < heightAt(p.x) / 2;
root.style.cursor = onPhoto ? "pointer" : "";
};
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
pid = e.pointerId;
gsap.killTweensOf(strip);
strip.tween = false;
strip.drag = true;
sx = lx = e.clientX;
so = strip.off;
moved = 0;
lt = performance.now();
strip.v = 0;
};
const onUp = (e: PointerEvent) => {
if (e.pointerId !== pid) return;
pid = -1;
if (!strip.drag) return;
strip.drag = false;
if (moved < 5) {
const p = local(e);
if (Math.abs(p.y) > heightAt(p.x) / 2) return;
const id = Math.floor(uAt(p.x));
const inBulge = id === Math.floor(uAt(cx.x)) && Math.abs(fmod(uAt(cx.x), 1) - 0.5) < 0.2;
const it = items[fmod(id, n)];
if (inBulge && it?.href) window.location.href = it.href;
else toBulge(id);
swell.v += 1.6; // a little pop
return;
}
strip.v = clamp(-8, 8, strip.v);
};
const onLeave = () => {
cx.t = 0;
swell.t = 1;
root.style.cursor = "";
};
const onKey = (e: KeyboardEvent) => {
const cur = Math.floor(uAt(cx.x));
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
e.preventDefault();
toBulge(cur + (e.key === "ArrowRight" ? 1 : -1));
}
if (e.key === "Enter") {
const it = items[fmod(cur, n)];
if (it?.href) window.location.href = it.href;
}
};
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("pointercancel", onUp);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
gsap.killTweensOf(strip);
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("pointercancel", onUp);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("keydown", onKey);
tex.dispose();
mat.dispose();
quad.geometry.dispose();
renderer.dispose();
canvas.remove();
};
}, [W, height, n, items, pinch, speed, background]);
const it = items[front];
const fs = Math.round(clamp(10, 14, height * 0.032));
return (
<div
ref={rootRef}
tabIndex={0}
role="region"
aria-roledescription="carousel"
aria-label="Products"
className={["relative w-full touch-pan-y overflow-hidden outline-none select-none", className].filter(Boolean).join(" ")}
style={{ height, background }}
>
<div ref={hostRef} aria-hidden="true" className="absolute inset-0" />
<div aria-live="polite" className="pointer-events-none absolute inset-x-0 bottom-[5%] flex items-baseline justify-center gap-3 text-white" style={{ fontSize: fs }}>
<span className="font-mono text-white/45 tabular-nums">
{String(front + 1).padStart(2, "0")} / {String(n).padStart(2, "0")}
</span>
{it?.title && <span className="font-medium tracking-[-0.01em]">{it.title}</span>}
</div>
</div>
);
}
export default PinchStrip;
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
6 propsitems{ src: string; title?: string; href?: string }[]The photos (cover-cropped, nearly square).heightnumberHeight, px.default 420default 420pinchnumberHow thin the band pinches (0 closes it, 1 is flat).default 0.4default 0.4speednumberSlide speed, photos per second.default 0.18default 0.18backgroundstringBackground.default "#000000"default "#000000"classNamestringExtra classes.