Try 'magnetic button'
View code

Specification

Catalogue
No. 61 of 110
Interaction
Hover, Layout Animation
Element
Media
Preview
Live component
Imports
react 19.3.1
Added

Notes

Several services sit in one row of tall photos; the one you point at or focus widens to show its caption.

Five services in the space of one, each with a picture. Unlike a text accordion it opens by pointing, shows one at a time, and stacks on a phone.

Open panel grows to 4.5 shares, 450ms cubic-bezier(.22, 1, .36, 1); caption fades in after 150ms. Opens on hover (mouse), focus and tap; under 480px the panels stack and grow in height. Changed from the library: no parallax inside the image.

The names, figures and pictures in the demo are sample content; a real build uses the client's own.

Code

React and plain CSS
"use client";

import { useState } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "./accordion-gallery.css";

const S = "/samples";

const GARDENS = [
  { id: "design", title: "Garden design", note: "Plans drawn around how you use the space" },
  { id: "patio", title: "Patios", note: "Sandstone and porcelain, laid on a proper base" },
  { id: "planting", title: "Planting", note: "Beds that look after themselves" },
  { id: "lawn", title: "Lawns", note: "New turf or a tired lawn brought back" },
  { id: "fencing", title: "Fencing", note: "Closeboard and slatted, posts set in concrete" },
];

function AccordionGalleryDemo() {
  const [open, setOpen] = useState(0);
  return (
    <div className="dm">
      <ul className="ag" aria-label="Sample services">
        {GARDENS.map((g, i) => (
          <li key={g.id} className="ag-item" data-open={i === open || undefined}>
            <button
              type="button"
              className="ag-btn"
              aria-expanded={i === open}
              onClick={() => setOpen(i)}
              onFocus={() => setOpen(i)}
              onPointerEnter={(e) => e.pointerType === "mouse" && setOpen(i)}
            >
              <img src={`${S}/garden-${g.id}.svg`} alt="" draggable={false} />
              <span className="ag-cap">
                <strong>{g.title}</strong>
                <span>{g.note}</span>
              </span>
            </button>
          </li>
        ))}
      </ul>
    </div>
  );
}

// What a hovered card shows: the piece used the way a visitor would.
const TOUR: Tour = [
  { click: ".ag-btn", nth: 1 },
  { click: ".ag-btn", nth: 3 },
  { click: ".ag-btn", nth: 0 },
];

export default function AccordionGalleryEntry(props: LivePreviewProps) {
  return (
    <PieceStage {...props} label="Image panels that widen" sample tour={TOUR}>
      <AccordionGalleryDemo />
    </PieceStage>
  );
}

More like this

Photo grid that opens into the photo

Layout AnimationMedia and galleries

Before and after slider

DragMedia and galleries

Card stack that deals the next picture

Press, Layout AnimationMedia and galleries

Bookshelf

Press, Layout AnimationMedia and galleries

A photo for each option

PressTabs

Menu that opens into link cards

Press, Layout AnimationNavigation