Try 'magnetic button'
View code

Specification

Catalogue
No. 13 of 110
Interaction
Scroll, Text Animation
Element
Text
Preview
Live component
Imports
react 19.3.1
Added

Notes

One sentence holds on screen while its words fill in to full ink in reading order as the visitor scrolls.

The scroll sets the reading pace for the one line that matters most. The whole sentence is there from the start for screen readers and before script, and it finishes with room to spare.

Holds for 1.8 frame heights; words fill over the first 80%, then it rests finished. Unread words at 24% ink; each word's colour changes in 200ms. Read whole by screen readers; all words at full ink before script and under reduced motion. One per page at most. Here it scrolls inside its own frame.

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 "./text-reveal.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 STATEMENT = "We build websites for small businesses that want to be found, understood and booked, and we write every word with you, not for you.";

function TextRevealDemo() {
  const frame = useRef<HTMLDivElement>(null);
  const track = useRef<HTMLDivElement>(null);
  const reduced = useSafeReducedMotion();
  const p = useFrameProgress(frame, track);
  const words = STATEMENT.split(" ");
  // Words fill over the first 80% of the hold; the rest lets it sit, finished.
  const lit = reduced ? words.length : Math.round(Math.min(1, p / 0.8) * words.length);
  return (
    <Frame label="A statement that reads with the scroll" frame={frame} hint="Scroll inside: the words fill in as you go">
      <div ref={track} className="txr-track">
        <p className="txr-text" aria-label={STATEMENT}>
          <span>
            {words.map((w, i) => (
              <span key={i} aria-hidden="true" data-lit={i < lit || undefined}>
                {w}{" "}
              </span>
            ))}
          </span>
        </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 TextRevealEntry(props: LivePreviewProps) {
  return (
    <PieceStage {...props} label="Statement that reads with the scroll" tour={TOUR}>
      <TextRevealDemo />
    </PieceStage>
  );
}

More like this

Steps that scroll past a picture that holds

ScrollPage sections

Cards that stack as you scroll

ScrollCards and accordions

Header that steps aside

ScrollNavigation

Sweeping headline phrase

Text AnimationText and code

Hand-drawn emphasis

Text AnimationText and code

Sign-up that hands over the next issue

Type, FeedbackForms and inputs