Patterns

Zoom

Images zoom with pinch (or Ctrl + wheel), double-tap, double-click and the +, - and 0 keys, and pan while zoomed. Each viewer can set how far a double-tap zooms (step) and how far zoom goes (max), or turn zoom off.

Loading the live example…

zoom.tsx
import { itemLabel } from "@ogdakke/fluidbox";
import { Fluidbox, type FluidboxRootProps } from "@ogdakke/fluidbox/react";
import { photos } from "./data";

function Gallery({ zoom }: Pick<FluidboxRootProps, "zoom">) {
  return (
    <Fluidbox.Root items={photos} zoom={zoom}>
      <div className="pattern-grid">
        {photos.map((photo) => (
          <Fluidbox.Trigger
            key={photo.src}
            item={photo}
            className="pattern-thumb"
          >
            <img src={photo.src} alt={itemLabel(photo)} />
          </Fluidbox.Trigger>
        ))}
      </div>
    </Fluidbox.Root>
  );
}

export function Zoom() {
  return (
    <>
      {/* Double-click zooms to 3x; pinch and wheel stop at 6x. */}
      <Gallery zoom={{ step: 3, max: 6 }} />
      <Gallery zoom={false} />
    </>
  );
}
  • zoom: { step, max } or zoom: false on the viewer. The custom elements also read the zoom-step, zoom-max and nozoom attributes.
  • Zoom options apply live, even while the viewer is open. Call fluidbox.update({ zoom }), or set a new zoom prop or property. Turning zoom off zooms a zoomed photo back out.
  • step defaults to 2 and max to 4.
  • While zoomed, the dialog has data-zoomed. Pans can reach under the browser's bars; set --fluidbox-zoom-bleed: 0px to keep them inside the window, or --fluidbox-zoom-clip to keep them inside the stage insets.