Scroll Spy

A table of contents whose marker glides to the section you're reading.

no dependenciesMIT · free

Introduction

Scroll this column; the marker on the right follows.

Installation

Scroll this column; the marker on the right follows.

Usage

Scroll this column; the marker on the right follows.

Props

Scroll this column; the marker on the right follows.

Installation

npx shadcn@latest add https://ombakui.com/r/scroll-spy.json

Usage

import { ScrollSpy } from "@/components/scroll-spy";

<aside className="sticky top-24">
  <ScrollSpy items={[{ id: "intro", label: "Introduction" }, { id: "usage", label: "Usage" }]} />
</aside>

Props

PropTypeDefaultDescription
items*ScrollSpyItem[]–Sections to track, in page order.
scrollContainerReact.RefObject<HTMLElement | null>–Use a scrollable element instead of the window, e.g. for demos.
titlestring"On this page"Heading above the list.
classNamestring–