Try 'magnetic button'
View code

Number 36: Scroll-linked feature list

Specification

Catalogue
No. 36 of 110
Interaction
Scroll
Preview
Live component
Imports
react 19.3.1
Added

Notes

As each feature passes the middle of the frame, it brightens and the visual beside it changes shape. An IntersectionObserver with a -45% margin top and bottom turns the middle tenth of the scroller into the trigger line.

The shape is one element whose border radius, width and rotation transition between three states. The small counter rolls through 01 to 03 in a one-line window.

The frame scrolls on its own with overscroll-behavior: contain, so reaching its end does not drag the page with it.

Code

React and plain CSS
"use client";

import { useEffect, useRef, useState, type CSSProperties } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import styles from "./feature-scroll.module.css";

const FEATURES = [
  { title: "Draft together", text: "Everyone edits the same page, and every change is named." },
  { title: "Review in place", text: "Comments sit next to the line they are about." },
  { title: "Ship on time", text: "Due dates turn amber two days out, then red." },
];

export default function FeatureScroll({ active, context }: LivePreviewProps) {
  const scrollRef = useRef<HTMLDivElement>(null);
  const [current, setCurrent] = useState(0);
  const demo = active && context === "card";

  // The feature closest to the middle of the scroller is the current one.
  useEffect(() => {
    const root = scrollRef.current;
    if (!root) return;
    const blocks = [...root.querySelectorAll<HTMLElement>("[data-feature]")];
    const observer = new IntersectionObserver(
      (records) => {
        for (const record of records) {
          if (record.isIntersecting) setCurrent(Number((record.target as HTMLElement).dataset.feature));
        }
      },
      { root, rootMargin: "-45% 0px -45% 0px" },
    );
    blocks.forEach((b) => observer.observe(b));
    return () => observer.disconnect();
  }, []);

  // Card demo: step through the features by scrolling the inner frame.
  useEffect(() => {
    const root = scrollRef.current;
    if (!root) return;
    if (!demo) {
      root.scrollTo({ top: 0 });
      return;
    }
    let index = 0;
    const id = window.setInterval(() => {
      index = (index + 1) % FEATURES.length;
      const block = root.querySelector<HTMLElement>(`[data-feature="${index}"]`);
      root.scrollTo({ top: block ? block.offsetTop - (root.clientHeight - block.offsetHeight) / 2 : 0, behavior: "smooth" });
    }, 1300);
    return () => window.clearInterval(id);
  }, [demo]);

  return (
    <div className={styles.root}>
      <div ref={scrollRef} className={styles.scroller} role="region" tabIndex={context === "card" ? -1 : 0} aria-label="Features, scroll to read">
        <div className={styles.spacer} aria-hidden="true" />
        {FEATURES.map((feature, i) => (
          <section key={feature.title} data-feature={i} className={styles.feature} data-current={i === current || undefined}>
            <h3 className={styles.title}>{feature.title}</h3>
            <p className={styles.text}>{feature.text}</p>
          </section>
        ))}
        <div className={styles.spacer} aria-hidden="true" />
      </div>
      <div className={styles.visual} aria-hidden="true">
        <span className={styles.shape} data-shape={current} />
        <span className={styles.index}>
          <span className={styles.indexColumn} style={{ "--n": current } as CSSProperties}>
            {FEATURES.map((_, i) => (
              <span key={i}>0{i + 1}</span>
            ))}
          </span>
        </span>
      </div>
    </div>
  );
}

More like this

Steps that scroll past a picture that holds

ScrollPage sections

Cards that stack as you scroll

ScrollCards and accordions

Tick slider with a wake

DragForms and inputs

Sliding tabs

Layout AnimationTabs

Smooth accordion

Layout AnimationCards and accordions

Strip that hints at more

ScrollNavigation