Try 'magnetic button'
View code

Number 30: Photo that opens to full width

Specification

Catalogue
No. 30 of 110
Interaction
Scroll
Element
Media
Preview
Live component
Imports
react 19.3.1
Added

Notes

A framed photo or video grows to the full width as the visitor scrolls through it, then rests.

A quiet way to give one image the whole screen at the moment the reader reaches it. Nothing sits on top of the picture.

Width from 62% to 100% and corner radius from 14px to 0 over the first 70% of a 1.5 frame-height hold. Caption fades in once it is full width. Full width and still under reduced motion. Changed from the library: no headline laid over the media.

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 { useRef, type CSSProperties, type ReactNode, type RefObject } from "react";
import { useFrameProgress } from "@/components/pieces/motion-helpers";
import { useSafeReducedMotion } from "@/components/pieces/kit/use-safe-reduced-motion";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "@/components/pieces/styles/scroll-frame.css";
import "./scroll-expand.css";

function Frame({ label, frame, children, hint }: { label: string; frame: RefObject<HTMLDivElement | null>; children: ReactNode; hint: string }) {
  return (
    <div className="dm dm-scroll">
      <div ref={frame} className="sf" tabIndex={0} role="region" aria-label={`${label}. Scroll inside this frame`}>
        {children}
      </div>
      <p className="dm-hint">{hint}</p>
    </div>
  );
}

function ScrollExpandDemo() {
  const frame = useRef<HTMLDivElement>(null);
  const track = useRef<HTMLDivElement>(null);
  const reduced = useSafeReducedMotion();
  const p = useFrameProgress(frame, track);
  // Grows over the first 70% of the hold, then rests at full width.
  const t = reduced ? 1 : Math.min(1, p / 0.7);
  return (
    <Frame label="A photo that opens with the scroll" frame={frame} hint="Scroll inside: the photo widens to the edges">
      <div className="sx">
        <p className="ss-intro">The finished kitchen</p>
        <div ref={track} className="sx-track">
          <div className="sx-hold">
            <figure className="sx-media" style={{ "--t": t } as CSSProperties}>
              <img src="/samples/kitchen-oak.svg" alt="The finished kitchen with oak units and a white tiled splashback" />
            </figure>
            <p className="sx-cap" data-on={t >= 1 || undefined}>
              Oak fronts, a quartz worktop and a white tiled splashback.
            </p>
          </div>
        </div>
        <p className="ss-outro">Then the page carries on.</p>
      </div>
    </Frame>
  );
}

// What a hovered card shows: the piece used the way a visitor would.
const TOUR: Tour = [
  { scroll: ".sf", to: 1, ms: 3600, wait: 1000 },
  { scroll: ".sf", to: 0, ms: 900, wait: 400 },
];

export default function ScrollExpandEntry(props: LivePreviewProps) {
  return (
    <PieceStage {...props} label="Photo that opens to full width" sample tour={TOUR}>
      <ScrollExpandDemo />
    </PieceStage>
  );
}

More like this

Header that steps aside

ScrollNavigation

Steps that scroll past a picture that holds

ScrollPage sections

Image panels that widen

Hover, Layout AnimationMedia and galleries

Photo grid that opens into the photo

Layout AnimationMedia and galleries

Focus carousel

ScrollMedia and galleries

Timeline with a line that fills

ScrollPage sections