Skip to content

Image Ripple

Image ripple effect with WebGL: your cursor drags a live water simulation that refracts the photo with a chromatic edge.

  • Scroll & Hover Effects
  • Travel / Hospitality
  • React only · 0 deps
  • 1 file
Full screen

Browser support · WebGL2 / WebGL1, no float-texture extensions needed. Without WebGL the image is shown still.

Install. One command, or copy the file.

$npx shadcn@latest add https://freedesignmd.com/r/image-ripple.json
  • Byte-identical to the preview
  • No Tailwind or config needed
  • SSR-safe · keyboard accessible
  • Respects reduced motion & transparency
components/effects/image-ripple.tsx
1/**
2 * ImageRipple, an image card that behaves like a shallow pool. The cursor
3 * drags a wake through a real-time wave simulation (ping-pong framebuffers,
4 * 16-bit heights packed into RGBA8 so it runs on every WebGL device), and the
5 * surface refracts the image with a slight chromatic split and a wet sheen.
6 *
7 * Props
8 * - src?: string Image URL (crossOrigin="anonymous", cover-fitted).
9 * - draw?: (ctx, w, h)=>void Procedural source drawn to an offscreen canvas (used when no src).
10 * - drawSize?: [w, h] Size of the procedural canvas. Default [800, 1000].
11 * - strength?: number Refraction amount. Default 1.
12 * - chroma?: number Chromatic split 0–1.5. Default 0.6.
13 * - damping?: number Wave energy kept per step (0.95–0.995). Default 0.986.
14 * - cell?: number Simulation cell size in CSS px, bigger = broader, cheaper waves. Default 2.
15 * - radius?: number Drop radius in CSS px. Default 14.
16 * - alt?: string Accessible description (canvas gets role="img").
17 * - children Overlay content (captions) above the image.
18 * CSS vars: --fd-ripple-radius.
19 *
20 * Browser support: WebGL2 / WebGL1 (no float-texture extensions needed).
21 * Without WebGL the image is shown still. Reduced motion: no simulation
22 * the image renders still. The loop sleeps once the water settles.
23 *
24 * Demo images: /img/lux/{hotel-golden,bamboo,dunes}.webp, included in the repo's public/img/lux
25 * copy them next to your page or swap in your own.
26 */
27import { useEffect, useRef, useState } from "react";
28import type { CSSProperties, ReactNode } from "react";
29
30type GL = WebGLRenderingContext | WebGL2RenderingContext;
31
32const HEAD = (gl2: boolean) =>
33 (gl2 ? "#version 300 es\n" : "") +
34 "#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n" +
35 (gl2 ? "#define texture2D texture\n#define gl_FragColor fdOut\nout vec4 fdOut;\n" : "");
36
37const CODEC = `
38float dec(vec2 c){ vec2 b = floor(c * 255. + .5); return (b.x * 256. + b.y) / 65535. * 2. - 1.; }
39vec2 enc(float v){ float x = floor(clamp(v * .5 + .5, 0., 1.) * 65535. + .5); float hi = floor(x / 256.); return vec2(hi, x - hi * 256.) / 255.; }
40`;
41
42const SIM = `
43uniform sampler2D uState;
44uniform vec2 uSimRes;
45uniform vec4 uDrops[4]; // sim px x, y, radius, strength
46uniform float uDamp;
47${CODEC}
48void main(){
49 vec2 t = 1. / uSimRes;
50 vec2 uv = gl_FragCoord.xy * t;
51 vec4 c = texture2D(uState, uv);
52 float h = dec(c.rg);
53 float p = dec(c.ba);
54 float n = dec(texture2D(uState, uv + vec2(t.x, 0.)).rg) + dec(texture2D(uState, uv - vec2(t.x, 0.)).rg)
55 + dec(texture2D(uState, uv + vec2(0., t.y)).rg) + dec(texture2D(uState, uv - vec2(0., t.y)).rg);
56 float nh = (n * .5 - p) * uDamp;
57 for (int i = 0; i < 4; i++) {
58 vec4 d = uDrops[i];
59 if (d.w == 0.) continue;
60 float r = length(gl_FragCoord.xy - d.xy) / d.z;
61 if (r < 1.) nh += d.w * (.5 + .5 * cos(3.14159 * r));
62 }
63 gl_FragColor = vec4(enc(nh), enc(h));
64}
65`;
66
67const DRAW = `
68uniform sampler2D uState;
69uniform sampler2D uImg;
70uniform vec2 uRes;
71uniform vec2 uSimRes;
72uniform vec2 uImgSize;
73uniform float uStrength;
74uniform float uChroma;
75${CODEC}
76float hAt(vec2 uv){
77 vec2 p = uv * uSimRes - .5;
78 vec2 i = floor(p);
79 vec2 f = p - i;
80 vec2 t = 1. / uSimRes;
81 float a = dec(texture2D(uState, (i + vec2(.5, .5)) * t).rg);
82 float b = dec(texture2D(uState, (i + vec2(1.5, .5)) * t).rg);
83 float c = dec(texture2D(uState, (i + vec2(.5, 1.5)) * t).rg);
84 float d = dec(texture2D(uState, (i + vec2(1.5, 1.5)) * t).rg);
85 return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
86}
87vec2 cover(vec2 uv){
88 float ra = uRes.x / uRes.y;
89 float ia = uImgSize.x / uImgSize.y;
90 vec2 s = ra > ia ? vec2(1., ia / ra) : vec2(ra / ia, 1.);
91 return (uv - .5) * s + .5;
92}
93void main(){
94 vec2 uv = gl_FragCoord.xy / uRes;
95 vec2 e = 1. / uSimRes;
96 float gx = hAt(uv + vec2(e.x, 0.)) - hAt(uv - vec2(e.x, 0.));
97 float gy = hAt(uv + vec2(0., e.y)) - hAt(uv - vec2(0., e.y));
98 vec2 g = vec2(gx, gy);
99 vec2 off = g * .06 * uStrength;
100 float ch = uChroma * .22;
101 vec3 col;
102 col.r = texture2D(uImg, cover(uv + off * (1. + ch))).r;
103 col.g = texture2D(uImg, cover(uv + off)).g;
104 col.b = texture2D(uImg, cover(uv + off * (1. - ch))).b;
105 // wet sheen: highlight minus the flat-surface baseline, plus soft slope shading
106 vec3 n = normalize(vec3(-g * 9., 1.));
107 vec3 H = normalize(vec3(-.35, .55, 1.));
108 float base = pow(H.z / length(H), 90.);
109 float spec = max(pow(max(dot(n, H), 0.), 90.) - base, 0.);
110 col += spec * .55;
111 col *= 1. + (gy - gx) * 1.4;
112 gl_FragColor = vec4(col, 1.);
113}
114`;
115
116const BLIT_VS = (gl2: boolean) => (gl2 ? "#version 300 es\nin vec2 aP;" : "attribute vec2 aP;") + "void main(){gl_Position=vec4(aP,0.,1.);}";
117
118export interface ImageRippleProps {
119 src?: string;
120 draw?: (ctx: CanvasRenderingContext2D, w: number, h: number) => void;
121 drawSize?: [number, number];
122 strength?: number;
123 chroma?: number;
124 damping?: number;
125 cell?: number;
126 radius?: number;
127 alt?: string;
128 className?: string;
129 style?: CSSProperties;
130 children?: ReactNode;
131}
132
133export function ImageRipple({
134 src,
135 draw,
136 drawSize = [800, 1000],
137 strength = 1,
138 chroma = 0.6,
139 damping = 0.986,
140 cell = 2,
141 radius = 14,
142 alt = "",
143 className,
144 style,
145 children,
146}: ImageRippleProps) {
147 const rootRef = useRef<HTMLDivElement>(null);
148 const canvasRef = useRef<HTMLCanvasElement>(null);
149 const stillRef = useRef<HTMLCanvasElement>(null);
150 const [failed, setFailed] = useState(false);
151 const live = useRef({ strength, chroma, damping, cell, radius });
152 live.current = { strength, chroma, damping, cell, radius };
153 const source = useRef<{ el: TexImageSource | null; w: number; h: number; dirty: boolean }>({ el: null, w: 1, h: 1, dirty: false });
154 const api = useRef<{ kick: () => void; drop: (x: number, y: number, s: number, r?: number) => void }>({ kick: () => {}, drop: () => {} });
155
156 // source image
157 useEffect(() => {
158 let cancelled = false;
159 const done = (el: TexImageSource, w: number, h: number) => {
160 source.current = { el, w, h, dirty: true };
161 api.current.kick();
162 const still = stillRef.current;
163 if (still) {
164 const r = still.getBoundingClientRect();
165 still.width = Math.max(1, Math.round(r.width));
166 still.height = Math.max(1, Math.round(r.height));
167 const c = still.getContext("2d");
168 if (c) {
169 const s = Math.max(still.width / w, still.height / h);
170 c.drawImage(el as CanvasImageSource, (still.width - w * s) / 2, (still.height - h * s) / 2, w * s, h * s);
171 }
172 }
173 };
174 if (src) {
175 const img = new Image();
176 img.crossOrigin = "anonymous";
177 img.decoding = "async";
178 img.onload = () => !cancelled && done(img, img.naturalWidth, img.naturalHeight);
179 img.src = src;
180 } else if (draw) {
181 const c = document.createElement("canvas");
182 c.width = drawSize[0];
183 c.height = drawSize[1];
184 const ctx = c.getContext("2d");
185 if (ctx) draw(ctx, c.width, c.height);
186 done(c, c.width, c.height);
187 }
188 return () => {
189 cancelled = true;
190 };
191 // eslint-disable-next-line react-hooks/exhaustive-deps
192 }, [src, draw, drawSize[0], drawSize[1], failed]);
193
194 // GL
195 useEffect(() => {
196 const canvas = canvasRef.current;
197 if (!canvas) return;
198 const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
199 const attrs: WebGLContextAttributes = { antialias: false, alpha: false, preserveDrawingBuffer: false };
200 let gl: GL | null = canvas.getContext("webgl2", attrs) as WebGL2RenderingContext | null;
201 const gl2 = !!gl;
202 if (!gl) gl = canvas.getContext("webgl", attrs) as WebGLRenderingContext | null;
203 if (!gl) {
204 setFailed(true);
205 return;
206 }
207 const g = gl;
208 const build = (fs: string) => {
209 const mk = (type: number, s: string) => {
210 const sh = g.createShader(type)!;
211 g.shaderSource(sh, s);
212 g.compileShader(sh);
213 if (!g.getShaderParameter(sh, g.COMPILE_STATUS)) console.warn("[ImageRipple]", g.getShaderInfoLog(sh));
214 return sh;
215 };
216 const p = g.createProgram()!;
217 g.attachShader(p, mk(g.VERTEX_SHADER, BLIT_VS(gl2)));
218 g.attachShader(p, mk(g.FRAGMENT_SHADER, HEAD(gl2) + fs));
219 g.bindAttribLocation(p, 0, "aP");
220 g.linkProgram(p);
221 const u: Record<string, WebGLUniformLocation | null> = {};
222 for (const m of fs.matchAll(/uniform\s+\w+\s+(\w+)/g)) u[m[1]] = g.getUniformLocation(p, m[1]);
223 return { p, u, ok: !!g.getProgramParameter(p, g.LINK_STATUS) };
224 };
225 const sim = build(SIM);
226 const ren = build(DRAW);
227 if (!sim.ok || !ren.ok) {
228 setFailed(true);
229 return;
230 }
231 const buf = g.createBuffer();
232 g.bindBuffer(g.ARRAY_BUFFER, buf);
233 g.bufferData(g.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), g.STATIC_DRAW);
234 g.enableVertexAttribArray(0);
235 g.vertexAttribPointer(0, 2, g.FLOAT, false, 0, 0);
236
237 const tex = (filter: number) => {
238 const t = g.createTexture()!;
239 g.bindTexture(g.TEXTURE_2D, t);
240 g.texParameteri(g.TEXTURE_2D, g.TEXTURE_MIN_FILTER, filter);
241 g.texParameteri(g.TEXTURE_2D, g.TEXTURE_MAG_FILTER, filter);
242 g.texParameteri(g.TEXTURE_2D, g.TEXTURE_WRAP_S, g.CLAMP_TO_EDGE);
243 g.texParameteri(g.TEXTURE_2D, g.TEXTURE_WRAP_T, g.CLAMP_TO_EDGE);
244 return t;
245 };
246 const imgTex = tex(g.LINEAR);
247 g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, 1, 1, 0, g.RGBA, g.UNSIGNED_BYTE, new Uint8Array([20, 22, 26, 255]));
248 let states: { t: WebGLTexture; f: WebGLFramebuffer }[] = [];
249 let cur = 0;
250 let SW = 1;
251 let SH = 1;
252 let W = 1;
253 let H = 1;
254 let dpr = 1;
255 const drops: number[][] = [];
256 let raf = 0;
257 let last = 0;
258 let awakeUntil = 0;
259 let visible = true;
260 let acc = 0;
261
262 const allocSim = () => {
263 for (const s of states) {
264 g.deleteTexture(s.t);
265 g.deleteFramebuffer(s.f);
266 }
267 SW = Math.max(8, Math.round(W / live.current.cell));
268 SH = Math.max(8, Math.round(H / live.current.cell));
269 // neutral height (0) encodes to 0x7FFF / 0x8000 → bytes [127/128, 255/0]
270 const init = new Uint8Array(SW * SH * 4);
271 for (let i = 0; i < init.length; i += 4) {
272 init[i] = 128;
273 init[i + 1] = 0;
274 init[i + 2] = 128;
275 init[i + 3] = 0;
276 }
277 states = [0, 1].map(() => {
278 const t = tex(g.NEAREST);
279 g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, SW, SH, 0, g.RGBA, g.UNSIGNED_BYTE, init);
280 const f = g.createFramebuffer()!;
281 g.bindFramebuffer(g.FRAMEBUFFER, f);
282 g.framebufferTexture2D(g.FRAMEBUFFER, g.COLOR_ATTACHMENT0, g.TEXTURE_2D, t, 0);
283 return { t, f };
284 });
285 g.bindFramebuffer(g.FRAMEBUFFER, null);
286 };
287
288 const step = () => {
289 const src = states[cur];
290 const dst = states[1 - cur];
291 g.useProgram(sim.p);
292 g.bindFramebuffer(g.FRAMEBUFFER, dst.f);
293 g.viewport(0, 0, SW, SH);
294 g.activeTexture(g.TEXTURE0);
295 g.bindTexture(g.TEXTURE_2D, src.t);
296 g.uniform1i(sim.u.uState, 0);
297 g.uniform2f(sim.u.uSimRes, SW, SH);
298 g.uniform1f(sim.u.uDamp, live.current.damping);
299 const d = new Float32Array(16);
300 drops.splice(0, 4).forEach((v, i) => d.set(v, i * 4));
301 g.uniform4fv(sim.u.uDrops, d);
302 g.drawArrays(g.TRIANGLES, 0, 3);
303 cur = 1 - cur;
304 };
305
306 const render = () => {
307 const s = source.current;
308 g.bindFramebuffer(g.FRAMEBUFFER, null);
309 g.viewport(0, 0, canvas.width, canvas.height);
310 g.useProgram(ren.p);
311 g.activeTexture(g.TEXTURE1);
312 g.bindTexture(g.TEXTURE_2D, imgTex);
313 if (s.dirty && s.el) {
314 g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL, true);
315 try {
316 g.texImage2D(g.TEXTURE_2D, 0, g.RGBA, g.RGBA, g.UNSIGNED_BYTE, s.el);
317 } catch {
318 /* tainted (no CORS) */
319 }
320 g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL, false);
321 s.dirty = false;
322 }
323 g.activeTexture(g.TEXTURE0);
324 g.bindTexture(g.TEXTURE_2D, states[cur].t);
325 g.uniform1i(ren.u.uState, 0);
326 g.uniform1i(ren.u.uImg, 1);
327 g.uniform2f(ren.u.uRes, canvas.width, canvas.height);
328 g.uniform2f(ren.u.uSimRes, SW, SH);
329 g.uniform2f(ren.u.uImgSize, s.w, s.h);
330 g.uniform1f(ren.u.uStrength, live.current.strength);
331 g.uniform1f(ren.u.uChroma, live.current.chroma);
332 g.drawArrays(g.TRIANGLES, 0, 3);
333 };
334
335 const loop = (now: number) => {
336 raf = 0;
337 const dt = last ? Math.min(now - last, 50) : 16.7;
338 last = now;
339 // fixed 120 Hz sim so wave speed is frame-rate independent
340 acc += dt;
341 let n = 0;
342 while (acc >= 8.33 && n < 4) {
343 step();
344 acc -= 8.33;
345 n++;
346 }
347 if (n === 4) acc = 0;
348 render();
349 if (now < awakeUntil && visible && !document.hidden) raf = requestAnimationFrame(loop);
350 else last = 0;
351 };
352 const kick = (wake = 0) => {
353 awakeUntil = Math.max(awakeUntil, performance.now() + wake);
354 if (!raf) raf = requestAnimationFrame(loop);
355 };
356 api.current.kick = () => kick(0);
357 api.current.drop = (x, y, s, r) => {
358 if (reduced) return;
359 const k = live.current.cell;
360 drops.push([x / k, (H - y) / k, Math.max(1.5, (r ?? live.current.radius) / k), s]);
361 if (drops.length > 12) drops.splice(0, drops.length - 12);
362 kick(5000);
363 };
364
365 const resize = () => {
366 const r = canvas.getBoundingClientRect();
367 W = Math.max(1, r.width);
368 H = Math.max(1, r.height);
369 dpr = Math.min(window.devicePixelRatio || 1, 2);
370 canvas.width = Math.round(W * dpr);
371 canvas.height = Math.round(H * dpr);
372 allocSim();
373 kick(0);
374 };
375 const ro = new ResizeObserver(resize);
376 ro.observe(canvas);
377 const io = new IntersectionObserver(([e]) => {
378 visible = e.isIntersecting;
379 if (visible) kick(0);
380 });
381 io.observe(canvas);
382 const onVis = () => !document.hidden && kick(0);
383 const onLost = (e: Event) => {
384 e.preventDefault();
385 cancelAnimationFrame(raf);
386 raf = 0;
387 setFailed(true);
388 };
389 document.addEventListener("visibilitychange", onVis);
390 canvas.addEventListener("webglcontextlost", onLost);
391 return () => {
392 cancelAnimationFrame(raf);
393 ro.disconnect();
394 io.disconnect();
395 document.removeEventListener("visibilitychange", onVis);
396 canvas.removeEventListener("webglcontextlost", onLost);
397 for (const s of states) {
398 g.deleteTexture(s.t);
399 g.deleteFramebuffer(s.f);
400 }
401 g.deleteTexture(imgTex);
402 g.deleteBuffer(buf);
403 g.deleteProgram(sim.p);
404 g.deleteProgram(ren.p);
405 api.current = { kick: () => {}, drop: () => {} };
406 };
407 }, [cell]);
408
409 // pointer → wake
410 useEffect(() => {
411 const el = rootRef.current;
412 if (!el) return;
413 let lx = -1;
414 let ly = -1;
415 let lt = 0;
416 const local = (e: PointerEvent) => {
417 const r = el.getBoundingClientRect();
418 return [e.clientX - r.left, e.clientY - r.top];
419 };
420 const move = (e: PointerEvent) => {
421 const [x, y] = local(e);
422 const now = performance.now();
423 if (lx < 0) {
424 lx = x;
425 ly = y;
426 lt = now;
427 return;
428 }
429 const dist = Math.hypot(x - lx, y - ly);
430 const spacing = live.current.radius * 0.6;
431 if (dist < spacing) return;
432 const v = Math.min(dist / Math.max(1, now - lt), 3);
433 // stamp drops along the segment so fast moves leave a continuous wake
434 const steps = Math.min(4, Math.ceil(dist / spacing));
435 for (let i = 1; i <= steps; i++) {
436 const t = i / steps;
437 api.current.drop(lx + (x - lx) * t, ly + (y - ly) * t, 0.08 + 0.09 * v);
438 }
439 lx = x;
440 ly = y;
441 lt = now;
442 };
443 const down = (e: PointerEvent) => {
444 const [x, y] = local(e);
445 api.current.drop(x, y, 0.55, live.current.radius * 1.6);
446 };
447 const leave = () => {
448 lx = -1;
449 };
450 el.addEventListener("pointermove", move);
451 el.addEventListener("pointerdown", down);
452 el.addEventListener("pointerleave", leave);
453 return () => {
454 el.removeEventListener("pointermove", move);
455 el.removeEventListener("pointerdown", down);
456 el.removeEventListener("pointerleave", leave);
457 };
458 }, []);
459
460 return (
461 <div ref={rootRef} className={`fd-ripple${className ? " " + className : ""}`} style={style}>
462 <style>{css}</style>
463 {failed ? (
464 <canvas ref={stillRef} className="fd-ripple-canvas" role={alt ? "img" : undefined} aria-label={alt || undefined} aria-hidden={alt ? undefined : true} />
465 ) : (
466 <canvas ref={canvasRef} className="fd-ripple-canvas" role={alt ? "img" : undefined} aria-label={alt || undefined} aria-hidden={alt ? undefined : true} />
467 )}
468 {children ? <div className="fd-ripple-overlay">{children}</div> : null}
469 </div>
470 );
471}
472
473const css = `
474.fd-ripple, .fd-ripple *, .fd-ripple *::before, .fd-ripple *::after { box-sizing: border-box; }
475.fd-ripple {
476 position: relative; display: block; margin: 0; padding: 0; border: 0; overflow: hidden;
477 border-radius: var(--fd-ripple-radius, 24px); background: #14161A; color: inherit; isolation: isolate; touch-action: pan-y;
478}
479.fd-ripple-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; }
480.fd-ripple-overlay { position: absolute; inset: 0; margin: 0; padding: 0; pointer-events: none; }
481.fd-ripple-overlay a, .fd-ripple-overlay button { pointer-events: auto; }
482`;
483
484/* ───────────────────────── demo ───────────────────────── */
485
486const SCENES: { desc: string; place: string; country: string; coords: string; nights: string; price: string; src: string }[] = [
487 { desc: "pastel houses stacked up a hillside above the sea at sunset", place: "Positano", country: "Italy", coords: "40.63° N · 14.48° E", nights: "7 nights", price: "from €3,450", src: "/img/halcyon/positano-sunset.webp" },
488 { desc: "sunlit bamboo grove with long shadows", place: "Arashiyama", country: "Japan", coords: "35.01° N · 135.67° E", nights: "9 nights", price: "from €4,980", src: "/img/lux/bamboo.webp" },
489 { desc: "wind-carved golden desert dunes at dusk", place: "Wadi Rum", country: "Jordan", coords: "29.57° N · 35.42° E", nights: "6 nights", price: "from €2,890", src: "/img/lux/dunes.webp" },
490];
491
492export function Demo() {
493 const [order, setOrder] = useState([0, 1, 2]);
494 const next = () => setOrder(([a, ...rest]) => [...rest, a]);
495 const top = SCENES[order[0]];
496 return (
497 <section className="fd-ripple-demo">
498 <style>{demoCss}</style>
499 <div className="fd-ripple-demo-copy">
500 <p className="fd-ripple-demo-kicker">Slowtrail · Winter 2026 collection</p>
501 <h1 className="fd-ripple-demo-title">Places that make you stop scrolling.</h1>
502 <p className="fd-ripple-demo-body">Small-group journeys to the world's quietest edges. Run your cursor over the water, then plan the trip you've been putting off.</p>
503 <div className="fd-ripple-demo-row">
504 <a className="fd-ripple-demo-cta" href="#book" onClick={(e) => e.preventDefault()}>Explore {top.place}</a>
505 <button type="button" className="fd-ripple-demo-next" onClick={next} aria-label="Next destination">
506 <svg width="18" height="18" viewBox="0 0 18 18" aria-hidden="true"><path d="M4 9h10M10 5l4 4-4 4" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" /></svg>
507 </button>
508 <span className="fd-ripple-demo-count" aria-live="polite">{String(order[0] + 1).padStart(2, "0")} / {String(SCENES.length).padStart(2, "0")}</span>
509 </div>
510 </div>
511 <div className="fd-ripple-demo-stack">
512 {SCENES.map((s, i) => {
513 const pos = order.indexOf(i);
514 return (
515 <ImageRipple
516 key={s.place}
517 className="fd-ripple-demo-card"
518 src={s.src}
519 alt={`${s.place}, ${s.country}: ${s.desc}`}
520 style={{ ["--pos" as string]: pos, zIndex: SCENES.length - pos } as CSSProperties}
521 >
522 <div className="fd-ripple-demo-cap">
523 <span className="fd-ripple-demo-coords">{s.coords}</span>
524 <span className="fd-ripple-demo-place">{s.place}</span>
525 <span className="fd-ripple-demo-country">{s.country}</span>
526 <span className="fd-ripple-demo-meta">
527 <span>{s.nights}</span>
528 <span>{s.price}</span>
529 </span>
530 </div>
531 </ImageRipple>
532 );
533 })}
534 </div>
535 </section>
536 );
537}
538
539const demoCss = `
540.fd-ripple-demo, .fd-ripple-demo *, .fd-ripple-demo *::before, .fd-ripple-demo *::after { box-sizing: border-box; }
541.fd-ripple-demo {
542 --fd-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
543 --fd-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
544 min-height: 100vh; margin: 0; padding: clamp(32px, 6vw, 88px) clamp(20px, 5vw, 72px);
545 display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: clamp(40px, 6vw, 96px);
546 background: #F3F0EA; color: #16181D; overflow: hidden;
547 font: 400 15px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
548}
549.fd-ripple-demo-copy { max-width: 480px; justify-self: end; margin: 0; padding: 0; }
550.fd-ripple-demo-kicker { margin: 0 0 18px; padding: 0; color: #8A6A4E; font: 600 12px/1.3 ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace; letter-spacing: 0.1em; text-transform: uppercase; }
551.fd-ripple-demo-title { margin: 0 0 20px; padding: 0; color: #16181D; font: 700 clamp(2.5rem, 4.6vw, 4.25rem)/1 "SF Pro Display", ui-sans-serif, -apple-system, "Inter", "Segoe UI", Roboto, sans-serif; letter-spacing: -0.04em; }
552.fd-ripple-demo-body { max-width: 42ch; margin: 0 0 32px; padding: 0; color: #575A63; font: 400 1.0625rem/1.55 ui-sans-serif, -apple-system, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif; letter-spacing: -0.01em; }
553.fd-ripple-demo-row { display: flex; align-items: center; gap: 12px; margin: 0; padding: 0; }
554.fd-ripple-demo-cta {
555 display: inline-flex; align-items: center; height: 50px; margin: 0; padding: 0 26px; border: 0; border-radius: 9999px;
556 background: #16181D; color: #F7F5F0; text-decoration: none;
557 font: 600 15px/1 ui-sans-serif, -apple-system, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif; letter-spacing: -0.01em;
558 transition: transform 120ms var(--fd-ease-out), background 120ms var(--fd-ease-out);
559}
560.fd-ripple-demo-cta:hover { background: #2C2F37; }
561.fd-ripple-demo-cta:active, .fd-ripple-demo-next:active { transform: scale(0.96); }
562.fd-ripple-demo-next {
563 appearance: none; -webkit-appearance: none; display: inline-flex; align-items: center; justify-content: center;
564 width: 50px; height: 50px; margin: 0; padding: 0; border: 1px solid rgba(22,24,29,.16); border-radius: 9999px;
565 background: transparent; color: #16181D; cursor: pointer; font: inherit;
566 transition: transform 120ms var(--fd-ease-out), background 120ms var(--fd-ease-out);
567}
568.fd-ripple-demo-next svg { display: block; }
569.fd-ripple-demo-next:hover { background: rgba(22,24,29,.06); }
570.fd-ripple-demo-cta:focus-visible, .fd-ripple-demo-next:focus-visible { outline: 2px solid rgba(0,122,255,.7); outline-offset: 2px; }
571.fd-ripple-demo-count { margin: 0 0 0 6px; padding: 0; color: #8A8D96; font: 500 13px/1 ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
572.fd-ripple-demo-stack { position: relative; justify-self: start; width: min(100%, 420px); aspect-ratio: 4 / 5; margin: 0; padding: 0; }
573.fd-ripple-demo-stack .fd-ripple-demo-card {
574 position: absolute; inset: 0; --fd-ripple-radius: 28px;
575 transform: translate(calc(var(--pos) * 34px), calc(var(--pos) * -18px)) rotate(calc(var(--pos) * 4deg)) scale(calc(1 - var(--pos) * 0.06));
576 filter: brightness(calc(1 - var(--pos) * 0.12));
577 box-shadow: 0 1px 2px rgba(22,24,29,.1), 0 30px 60px -24px rgba(22,24,29,.45);
578 transition: transform 420ms var(--fd-spring), filter 420ms var(--fd-ease-out);
579 cursor: crosshair;
580}
581.fd-ripple-demo-cap {
582 position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; margin: 0; padding: 72px 24px 22px;
583 background: linear-gradient(180deg, rgba(8,10,14,0) 0%, rgba(8,10,14,.55) 55%, rgba(8,10,14,.72) 100%); color: #FFFFFF;
584}
585.fd-ripple-demo-coords { margin: 0 0 8px; padding: 0; color: rgba(255,255,255,.72); font: 500 11px/1 ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace; letter-spacing: .08em; }
586.fd-ripple-demo-place { margin: 0; padding: 0; color: #FFFFFF; font: 700 2rem/1 "SF Pro Display", ui-sans-serif, -apple-system, "Inter", "Segoe UI", Roboto, sans-serif; letter-spacing: -0.03em; }
587.fd-ripple-demo-country { margin: 6px 0 16px; padding: 0; color: rgba(255,255,255,.85); font: 500 15px/1.3 ui-sans-serif, -apple-system, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif; }
588.fd-ripple-demo-meta { display: flex; justify-content: space-between; margin: 0; padding: 14px 0 0; border-top: 1px solid rgba(255,255,255,.25); color: #FFFFFF; font: 500 13px/1 ui-sans-serif, -apple-system, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif; }
589.fd-ripple-demo-meta span { margin: 0; padding: 0; }
590@media (max-width: 860px) {
591 .fd-ripple-demo { grid-template-columns: 1fr; }
592 .fd-ripple-demo-copy { justify-self: start; }
593 .fd-ripple-demo-stack { justify-self: center; width: min(78%, 360px); margin-right: 40px; }
594}
595@media (prefers-reduced-motion: reduce) { .fd-ripple-demo-card { transition: none; } }
596`;

More Scroll & Hover Effects. Same file contract.

Scroll Split Card, effects preview: Scroll animation card in React: a pinned card splits into three panels that fan out in 3D and flip to reveal…

Scroll Split Card

Scroll animation card in React: a pinned card splits into three panels that fan out in 3D and flip to reveal services.

Hover Transitions, effects preview: Eight hover effects for React profile cards: morph blob, diagonal wipe, pixel dissolve, iris, slices, focus…

Hover Transitions

Eight hover effects for React profile cards: morph blob, diagonal wipe, pixel dissolve, iris, slices, focus and a liquid lens.

Sticky Storytelling, effects preview: Scrollytelling section for React: pinned media morphs between four states while text steps scroll past a…

Sticky Storytelling

Scrollytelling section for React: pinned media morphs between four states while text steps scroll past a progress rail.

Questions about Image Ripple

Run npx shadcn@latest add https://freedesignmd.com/r/image-ripple.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.

Image ripple effect with WebGL: your cursor drags a live water simulation that refracts the photo with a chromatic edge. 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.

WebGL2 / WebGL1, no float-texture extensions needed. Without WebGL the image is shown still.

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.