Number 79: Steps that scroll past a picture that holds
Specification
- Catalogue
- No. 79 of 110
- Section
- Page sections
- Interaction
- Scroll
- Preview
- Live component
- Imports
- react 19.3.1
- Added
Notes
The steps of a process scroll by while one picture holds still and changes with each step.
The scroll is the story: each step gets its own stretch of scrolling, the picture shows that step, and the last one stays long enough to be seen before the section lets go.
Picture holds with CSS position: sticky; no scroll-jacking. Each step gets 70% of the frame's height of scrolling; the last keeps the final 30% of the distance. Here it scrolls inside its own frame. On a full page use the kit's ScrollStory: about 0.75 screen per stage on a wide screen, 0.85 on a phone, then check with pace.mjs. Under 480px and under reduced motion nothing holds: each picture sits after its text. Changed from the library: no dark gradient panels or background colour change.
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 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 "./sticky-scroll.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>
);
}
const PROCESS = [
{ title: "Map", body: "We list every page and what each one must do, from your notes and one call." },
{ title: "Design", body: "Layouts for the main pages in your colours, for you to react to before anything is built." },
{ title: "Build", body: "The real site, coded and checked on phones as well as laptops." },
{ title: "Launch", body: "We go live together and stay on hand for the changes you spot after." },
];
function SiteSketch({ stage }: { stage: number }) {
return (
<div className="sk" data-stage={stage} aria-hidden="true">
<div className="sk-bar">
<i />
<i />
<i />
<span>{stage >= 3 ? "yourbusiness.co.uk" : "draft"}</span>
</div>
<div className="sk-body">
<div className="sk-map">
<b>Home</b>
<span>
<b>Services</b>
<b>About</b>
<b>Contact</b>
</span>
</div>
<div className="sk-page">
<i className="sk-h" />
<i className="sk-l" />
<i className="sk-l sk-short" />
<i className="sk-btn" />
<div className="sk-cards">
<i />
<i />
<i />
</div>
</div>
</div>
</div>
);
}
function StickyScrollDemo() {
const frame = useRef<HTMLDivElement>(null);
const track = useRef<HTMLDivElement>(null);
const reduced = useSafeReducedMotion();
const p = useFrameProgress(frame, track);
const last = PROCESS.length - 1;
// As in the kit: the last stage keeps the final 30% so the result is seen before release.
const stage = p >= 0.7 ? last : Math.min(last - 1, Math.floor((p / 0.7) * last));
return (
<Frame label="How a website project runs" frame={frame} hint="Scroll inside: the picture holds while the steps pass">
<div className="ss" data-flat={reduced || undefined}>
<p className="ss-intro">How a website project runs</p>
<div ref={track} className="ss-track">
<ol className="ss-steps">
{PROCESS.map((s, i) => (
<li key={s.title} className="ss-step" data-on={i === stage || undefined}>
<h3>
<span>{i + 1}</span> {s.title}
</h3>
<p>{s.body}</p>
<div className="ss-inline">
<SiteSketch stage={i} />
</div>
</li>
))}
</ol>
<div className="ss-hold">
<SiteSketch stage={stage} />
</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 StickyScrollEntry(props: LivePreviewProps) {
return (
<PieceStage {...props} label="Steps that scroll past a picture that holds" sample tour={TOUR}>
<StickyScrollDemo />
</PieceStage>
);
}