Kinetic UI
Back to Introduction
General

Scroll Spy

A navigation indicator that tracks scroll position and highlights the active section.

Quick Actions
CLI Installation
npx kinetic-ui-cli@latest add scroll-spy
scroll-spy

Section 1: Introduction

Scroll down to see the indicator on the side update automatically based on your scroll position.

Section 2: Features

The scroll spy component tracks which section is currently active in the viewport.

Section 3: Pricing

You can also click on the dots on the side to smoothly scroll to this specific section.

Section 4: Contact

End of the scrollable content area.

Overview

The ScrollSpy component is an essential wayfinding tool for single-page applications or long-scrolling marketing sites. It automatically tracks the user's scroll position and highlights the currently active section dot. Clicking on any dot smoothly scrolls the page to that specific section.

Usage

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

export default function Page() {
  const sections = [
    { id: "hero", label: "Introduction" },
    { id: "features", label: "Core Features" },
    { id: "pricing", label: "Pricing Plans" },
    { id: "contact", label: "Get in Touch" },
  ]

  return (
    <main>
      <ScrollSpy sections={sections} alignment="right" />
      
      <section id="hero" className="h-screen">...</section>
      <section id="features" className="h-screen">...</section>
      <section id="pricing" className="h-screen">...</section>
      <section id="contact" className="h-screen">...</section>
    </main>
  )
}

Usage Guide

1. Import the Component

Import the component into your React or Next.js page:

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

2. Implementation Example

Render the component and customize its behavior by passing props:

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

export default function Example() {
  return (
    <div className="w-full flex items-center justify-center p-8">
      <ScrollSpy
        sections{/* value */}
        scrollContainerRef{/* value */}
        alignment{/* value */}
      />
    </div>
  );
}
Performance Notes
  • Uses CSS hardware acceleration via GPU transform-binds.
  • Damped interpolation minimizes paint-redraw flashes.
  • Tree-shakable import: only compiles elements requested.
Accessibility Notes
  • Full keyboard focus-ring navigation support (`Tab`/`Shift+Tab`).
  • ARIA roles mapped correctly for assistive screen readers.
  • Respects `prefers-reduced-motion` system toggles.