← Components

Liquid image reveal

An organic reveal with SVG filters.

Cursor · FreeInstall ↓
Open preview ↗
Loading the demoNew tab ↗

Customize

2.2 s
80 px
0.020
3
0.50
0.50
0.0 s
Your code
<LiquidImageReveal src={src} alt={alt} />

Changes show live and stay in the address, so a link keeps them.

Code

"use client";

import { useCallback, useId, useRef, type CSSProperties } from "react";
import { gsap } from "gsap";
import { useGSAP } from "@gsap/react";

// An image that opens like a drop of liquid. A circle grows from a point and the image shows
// through it. The edge of the circle is pushed around by an SVG noise filter, so it wobbles like
// a puddle instead of a clean circle. Click it and the puddle closes, then opens again from
// wherever you clicked.

export type LiquidImageRevealProps = {
  /** The image address. */
  src: string;
  /** What the image shows. It becomes the accessible name of the whole piece. */
  alt: string;
  /** Width of the box: a number in pixels or any CSS length. It fills its parent by default. */
  width?: number | string;
  /** Height of the box: a number in pixels or any CSS length. It fills its parent by default. */
  height?: number | string;
  /** How long the reveal takes, in seconds. */
  duration?: number;
  /** Seconds to wait before the reveal starts. */
  delay?: number;
  /** The GSAP ease of the reveal, e.g. "power2.out" or "expo.out". */
  ease?: string;
  /** When the first reveal plays: "visible" waits until the image is scrolled into view, "mount" plays straight away. */
  trigger?: "visible" | "mount";
  /** Clicking (or pressing Enter on) the image closes the puddle and opens it again from that spot. */
  replayOnClick?: boolean;
  /** Where the puddle starts, across the box: 0 is the left edge, 0.5 the middle, 1 the right edge. */
  centerX?: number;
  /** Where the puddle starts, down the box: 0 is the top edge, 0.5 the middle, 1 the bottom edge. */
  centerY?: number;
  /** How big the circle gets, in pixels. Leave empty to grow just enough to cover the whole image. */
  maxRadius?: number;
  /** How fine the wobble is. Small numbers give big slow waves, large numbers give small ripples. */
  turbulenceFrequency?: number;
  /** Layers of detail in the wobble. More looks richer but costs more on phones. 2 to 4 is plenty. */
  turbulenceOctaves?: number;
  /** How far the noise pushes the edge, in pixels. 0 is a clean circle. */
  displacementScale?: number;
  /** Called every time a reveal finishes. */
  onComplete?: () => void;
  /** Extra classes for the outer box, e.g. a radius. */
  className?: string;
};

const toCss = (value: number | string) => (typeof value === "number" ? `${value}px` : value);

export function LiquidImageReveal({
  src,
  alt,
  width = "100%",
  height = "100%",
  duration = 2.2,
  delay = 0,
  ease = "power2.out",
  trigger = "visible",
  replayOnClick = true,
  centerX = 0.5,
  centerY = 0.5,
  maxRadius,
  turbulenceFrequency = 0.02,
  turbulenceOctaves = 3,
  displacementScale = 80,
  onComplete,
  className = "",
}: LiquidImageRevealProps) {
  const boxRef = useRef<HTMLElement | null>(null);
  const setBox = useCallback((node: HTMLElement | null) => {
    boxRef.current = node;
  }, []);
  const maskRef = useRef<SVGMaskElement>(null);
  const filterRef = useRef<SVGFilterElement>(null);
  const circleRef = useRef<SVGCircleElement>(null);

  // SVG ids can't hold the colons React puts in useId, and two copies on a page need different ids
  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
  const maskId = `liquid-mask-${uid}`;
  const filterId = `liquid-filter-${uid}`;

  // Values the animation reads while it runs. Only the callback is live; the look props restart the reveal
  // (see the dependencies below), so a new wobble is always shown by playing it, never hidden behind a finished mask.
  const live = useRef({ displacementScale, maxRadius, onComplete });
  live.current = { displacementScale, maxRadius, onComplete };

  useGSAP(
    (_context, contextSafe) => {
      const box = boxRef.current;
      const mask = maskRef.current;
      const filter = filterRef.current;
      const circle = circleRef.current;
      if (!box || !mask || !filter || !circle || !contextSafe) return;

      // progress: 0 is closed, 1 is fully open. The radius is worked out from it on every draw,
      // so a resize in the middle of a reveal still ends up covering the whole image.
      const state = { progress: 0 };
      const origin = { x: centerX, y: centerY };

      const draw = () => {
        const w = box.clientWidth;
        const h = box.clientHeight;
        const { displacementScale: scale, maxRadius: fixedRadius } = live.current;
        // The noise pulls pixels in from outside the box, so the filter and mask regions are a
        // little bigger than the box. Otherwise the edges would get transparent holes.
        const pad = Math.ceil(scale) + 2;
        for (const el of [mask, filter]) {
          el.setAttribute("x", String(-pad));
          el.setAttribute("y", String(-pad));
          el.setAttribute("width", String(w + pad * 2));
          el.setAttribute("height", String(h + pad * 2));
        }
        const cx = origin.x * w;
        const cy = origin.y * h;
        // The farthest corner, plus the most the noise can pull the edge back
        const farthest = Math.hypot(Math.max(cx, w - cx), Math.max(cy, h - cy)) + scale * 0.6;
        circle.setAttribute("cx", String(cx));
        circle.setAttribute("cy", String(cy));
        circle.setAttribute("r", String(state.progress * (fixedRadius ?? farthest)));
      };

      draw();
      const resizeObserver = new ResizeObserver(draw);
      resizeObserver.observe(box);

      // Reduced motion: no growing circle. The image is simply there.
      const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
      if (reduced) {
        state.progress = 1;
        draw();
        return () => resizeObserver.disconnect();
      }

      const open = (wait: number) => {
        gsap.to(state, {
          progress: 1,
          duration,
          delay: wait,
          ease,
          onUpdate: draw,
          onComplete: () => live.current.onComplete?.(),
        });
      };

      // Close quickly toward the old spot, then open again from the new one
      const reopenFrom = (x: number, y: number) => {
        gsap.killTweensOf(state);
        gsap.to(state, {
          progress: 0,
          duration: Math.min(0.6, duration * 0.3),
          ease: "power2.in",
          onUpdate: draw,
          onComplete: () => {
            origin.x = x;
            origin.y = y;
            open(0.05);
          },
        });
      };

      const onClick = contextSafe((event: MouseEvent) => {
        if (!replayOnClick) return;
        const rect = box.getBoundingClientRect();
        // A keyboard press has no position (detail is 0), so it reopens from the usual spot
        const fromKeyboard = event.detail === 0;
        const x = fromKeyboard ? centerX : (event.clientX - rect.left) / rect.width;
        const y = fromKeyboard ? centerY : (event.clientY - rect.top) / rect.height;
        reopenFrom(Math.min(1, Math.max(0, x)), Math.min(1, Math.max(0, y)));
      });
      box.addEventListener("click", onClick);

      // Wait until the image is on screen, so the reveal isn't spent while nobody is looking
      let visibility: IntersectionObserver | null = null;
      if (trigger === "visible" && typeof IntersectionObserver !== "undefined") {
        visibility = new IntersectionObserver(
          ([entry]) => {
            if (!entry?.isIntersecting) return;
            visibility?.disconnect();
            open(delay);
          },
          { threshold: 0.35 },
        );
        visibility.observe(box);
      } else {
        open(delay);
      }

      return () => {
        visibility?.disconnect();
        resizeObserver.disconnect();
        box.removeEventListener("click", onClick);
        gsap.killTweensOf(state);
      };
    },
    { scope: boxRef, dependencies: [duration, delay, ease, trigger, replayOnClick, centerX, centerY, displacementScale, turbulenceFrequency, turbulenceOctaves, maxRadius], revertOnUpdate: true },
  );

  const boxStyle: CSSProperties = { width: toCss(width), height: toCss(height) };

  const picture = (
    <svg className="absolute inset-0 block h-full w-full" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
      <defs>
        {/* The liquid edge: noise that pushes the circle's pixels around. sRGB keeps the push
            even in every direction. */}
        <filter id={filterId} filterUnits="userSpaceOnUse" colorInterpolationFilters="sRGB" ref={filterRef}>
          <feTurbulence type="fractalNoise" baseFrequency={turbulenceFrequency} numOctaves={turbulenceOctaves} result="noise" />
          <feDisplacementMap in="SourceGraphic" in2="noise" scale={displacementScale} xChannelSelector="R" yChannelSelector="G" />
        </filter>
        {/* White shows the image, black hides it. The growing circle is the white part. */}
        <mask id={maskId} maskUnits="userSpaceOnUse" ref={maskRef}>
          <circle ref={circleRef} r="0" fill="white" filter={`url(#${filterId})`} />
        </mask>
      </defs>
      <image href={src} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" mask={`url(#${maskId})`} />
    </svg>
  );

  const shared = `relative block overflow-hidden ${className}`;

  if (replayOnClick) {
    return (
      <button
        type="button"
        ref={setBox}
        aria-label={`${alt}. Press to replay the reveal.`}
        className={`${shared} cursor-pointer border-0 bg-transparent p-0 text-left focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-current`}
        style={boxStyle}
      >
        {picture}
      </button>
    );
  }

  return (
    <div ref={setBox} role="img" aria-label={alt} className={shared} style={boxStyle}>
      {picture}
    </div>
  );
}

The component. Installs to components/dimaac/liquid-image-reveal.tsx.

Install

With the shadcn CLI

npx shadcn@latest add https://ui.dimaac.com/r/liquid-image-reveal.json

It adds components/dimaac/liquid-image-reveal.tsx and installs what it imports. With the @dimaac namespace in components.json (Docs) it's just npx shadcn@latest add @dimaac/liquid-image-reveal.

By hand

npm install gsap @gsap/react
  1. Install the packages it uses: gsap, @gsap/react.
  2. Copy the component file below into components/dimaac/liquid-image-reveal.tsx.
  3. It's styled with Tailwind v4 classes. If that folder sits outside the places Tailwind scans, add it with @source in your CSS.
  4. Import it with import { LiquidImageReveal } from "@/components/dimaac/liquid-image-reveal". Give its parent a size: it fills it.

Props

PropTypeDefaultDescription
src (required)string-The image address.
alt (required)string-What the image shows. It becomes the accessible name of the whole piece.
widthnumber | string"100%"Width of the box: a number in pixels or any CSS length. It fills its parent by default.
heightnumber | string"100%"Height of the box: a number in pixels or any CSS length. It fills its parent by default.
durationnumber2.2How long the reveal takes, in seconds.
delaynumber0Seconds to wait before the reveal starts.
easestring"power2.out"The GSAP ease of the reveal, e.g. "power2.out" or "expo.out".
trigger"visible" | "mount""visible"When the first reveal plays: "visible" waits until the image is scrolled into view, "mount" plays straight away.
replayOnClickbooleantrueClicking (or pressing Enter on) the image closes the puddle and opens it again from that spot.
centerXnumber0.5Where the puddle starts, across the box: 0 is the left edge, 0.5 the middle, 1 the right edge.
centerYnumber0.5Where the puddle starts, down the box: 0 is the top edge, 0.5 the middle, 1 the bottom edge.
maxRadiusnumber-How big the circle gets, in pixels. Leave empty to grow just enough to cover the whole image.
turbulenceFrequencynumber0.02How fine the wobble is. Small numbers give big slow waves, large numbers give small ripples.
turbulenceOctavesnumber3Layers of detail in the wobble. More looks richer but costs more on phones. 2 to 4 is plenty.
displacementScalenumber80How far the noise pushes the edge, in pixels. 0 is a clean circle.
onComplete() => void-Called every time a reveal finishes.
classNamestring""Extra classes for the outer box, e.g. a radius.

Use with AI

Agent prompt

Paste it into Claude Code, Cursor or any coding agent, or open it straight in a chat. It carries your Customize settings.

Prompt
Add the Liquid image reveal component (<LiquidImageReveal />) from DiMaac UI to this project.

Docs: https://ui.dimaac.com/components/liquid-image-reveal
Source and dependencies (shadcn registry JSON): https://ui.dimaac.com/r/liquid-image-reveal.json

Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/liquid-image-reveal.json

Then use it like this:
import { LiquidImageReveal } from "@/components/dimaac/liquid-image-reveal";
<LiquidImageReveal src={src} alt={alt} />

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/liquid-image-reveal.tsx and install gsap, @gsap/react.
It uses Tailwind v4 classes, so make sure Tailwind scans that folder. Give its parent a size: it fills it. Keep light and dark mode working and keep its prefers-reduced-motion fallback.
Full index for agents: https://ui.dimaac.com/llms.txt

Files agents read

llms.txt
Every component and how to install it
liquid-image-reveal.md
This page as Markdown: install, props and the full source
liquid-image-reveal.json
The shadcn registry item

About

A photo revealed through a circle that grows from a point, with an edge that wobbles like a puddle because an SVG noise filter pushes it around. It plays when the image scrolls into view, and clicking (or pressing Enter on) it closes the puddle and opens it again from that exact spot. It fills any box, resizes cleanly, ids are unique so several can share a page, and with reduced motion the image is simply there. Ported from the first DiMaac UI and rebuilt with useGSAP: a responsive box instead of fixed pixels, light octaves by default so phones stay smooth, a real accessible name, and a replay.

Installs to
components/dimaac/liquid-image-reveal.tsx
Uses
gsap, @gsap/react
Tags
svg, gsap, image, reveal, mask, click

Photo: orange visor by West Kast on Lummi (Lummi License). Photo: lime blazer by Amino on Lummi (Lummi License). Photo: neon profile by Shaun Duval on Lummi (Lummi License).