Waypoint / Scrollspy
Highlights the navigation entry for the section currently in view as the user scrolls, driven by the useWaypoint composable. useScrollspy is the id-list helper: scrollspy.
Underline Variant
Overview of the current section with a compact underline indicator.
Pill Variant
Getting started stays selected while the card remains anchored in place.
API Reference
Wiring
import { ref } from 'vue';
import { useScrollspy, useWaypoint } from "@vanduo-oss/vd3";
const root = ref<HTMLElement | null>(null);
useWaypoint(root); // wires [data-vd-waypoint-nav] inside root; cleanup on unmount
// Or observe section IDs directly with useScrollspy:
const { activeId } = useScrollspy(['overview', 'features', 'pricing'], {
offset: 96,
});
// react to the active section changing on a waypoint nav
root.value?.addEventListener('waypoint:change', (e) => {
console.log('active', e.detail.activeId);
});CSS Classes
| Class | Description | Type |
|---|---|---|
.vd-waypoint-nav | Base scrollspy navigation container — required | Base |
.vd-waypoint-border | Adds a left border highlight on the active link (sidebar style) | Modifier |
.vd-waypoint-pill | Rounded pill-shaped background on the active link | Modifier |
.vd-waypoint-underline | Bottom underline indicator on the active link (tab style) | Modifier |
.is-active | Applied automatically to the currently visible section's link | State |
Data Attributes
| Attribute | Description | Default |
|---|---|---|
data-vd-waypoint-nav | Selector for the scrollable container to observe (e.g. "#content" or "window") | window |
data-vd-waypoint-offset | Pixel offset from the top to trigger activation earlier or later | 80 |
data-vd-scrollspy-nav | Alias for data-vd-waypoint-nav | — |
Composable API
| Symbol | Description |
|---|---|
useWaypoint(root) | Composable — wires every [data-vd-waypoint-nav] inside the root ref; highlights the link of the topmost visible section. Call once in setup(). |
useScrollspy(ids, options?) | Composable — observes document elements matching ids (string[]) via IntersectionObserver and returns { activeId: Ref<string | null> }. |
options.offset / options.rootMargin | Optional useScrollspy options: offset (number, default 96px) or custom IntersectionObserver rootMargin (default `-${offset}px 0px -60% 0px`). |
(automatic cleanup) | The IntersectionObserver and click listeners are removed on component unmount. |
Events
| Event | Description | Detail |
|---|---|---|
waypoint:change | Fired on the nav element when the active section changes | { activeId, link } |
Accessibility
- Wrap the links in a
<nav>with a descriptivearia-label(for examplearia-label="Table of contents") — the composable does not add a landmark role for you - Active link receives
aria-current="true"in addition to the.is-activeclass - Links use standard anchor elements for native keyboard navigation and focus management
- Smooth scrolling respects
prefers-reduced-motionmedia query - Section targets use semantic heading hierarchy for screen reader landmark navigation