Create

Layout

Scrollspy

New
Copy page View as Markdown Open in ChatGPT Open in Claude

Navigation that marks the section being read and scrolls to a section on click.

Usage#

app.component.ts
import { WDS_SCROLLSPY } from '@wds/angular/scrollspy';

Put wds-scrollspy-item links with href="#id" in wds-scrollspy. Without target it follows the page; with target (a selector) it follows that scrolling element. The active item is the last section whose top has passed the reading line (the top of the scrolling area plus offset), and the last one once the area is scrolled to the end.

Examples#

Default#

A table of contents next to a scrolling article (target="#spy-default"). Clicking an item scrolls its section to the top and moves focus to it.

Planning Gear Navigation Weather Camp Leave no trace

Planning

Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.

Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.

Gear

Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.

Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.

Navigation

A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.

At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.

Weather

Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.

Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.

Camp

Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.

Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.

Leave no trace

Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.

Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.

Levels#

level="2" indents an item under the one before it, for subsections. The levels only change the indent; the active item is still found by the position of each section.

Before you go Planning Gear On the trail Navigation Weather Overnight Camp Leave no trace

Before you go

Two things decide most days in the hills before anyone ties their boots.

The rest of this part covers what to plan and what to pack.

Planning

Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.

Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.

Gear

Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.

Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.

On the trail

Once you are walking, attention matters more than speed.

These two habits prevent most of the trouble on a day route.

Navigation

A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.

At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.

Weather

Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.

Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.

Overnight

Staying out after dark adds a few simple rules.

They protect you, the animals and the next people to camp here.

Camp

Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.

Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.

Leave no trace

Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.

Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.

Horizontal#

orientation="horizontal" lays the items out as a bar above the content; the active item scrolls into view inside the bar when it does not fit.

Planning Gear Navigation Weather Camp Leave no trace

Planning

Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.

Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.

Gear

Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.

Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.

Navigation

A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.

At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.

Weather

Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.

Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.

Camp

Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.

Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.

Leave no trace

Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.

Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.

Sticky header#

With a sticky header over the content, offset (here 56px) moves the reading line below it, both for marking the active section and for scrolling to one.

Planning Gear Navigation Weather Camp Leave no trace
Trail handbook

Planning

Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.

Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.

Gear

Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.

Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.

Navigation

A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.

At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.

Weather

Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.

Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.

Camp

Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.

Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.

Leave no trace

Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.

Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.

Reading progress#

wds-change reports the id of the section being read (active) and the one before (previous); here it drives a title and a wds-progress above the article.

PlanningGearNavigationWeather
Reading: Planning

Planning

Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.

Gear

Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.

Navigation

A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.

Weather

Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.

API References#

wds-scrollspy-item#

A link of a wds-scrollspy to one section of the page. It is marked (active attribute and aria-current="location") while its section is being read.

Attributes

AttributeTypeDefaultDescription
hrefstring''Link to the section: # and its id.
levelnumber1Nesting level from 1: each level indents the link in a vertical scrollspy (e.g. 2 for subsections).

Slots

SlotDescription
(default)Text of the link.

CSS parts (::part)

PartDescription
linkThe <a> element.

wds-scrollspy#

Navigation that marks the section being read. Each wds-scrollspy-item links to a section by href="#id"; the active one is the last section whose top has passed the reading line (the top of the scrolling area plus offset), and the last one once the area is scrolled to the end, so a short final section is reached too. It follows the page, or the scrolling element given by target. Clicking an item scrolls its section to the reading line (smoothly, unless the user prefers reduced motion) and moves focus to it.

Attributes

AttributeTypeDefaultDescription
targetstring''Selector of the scrolling element that holds the sections (looked up in the same document or shadow root). Empty: the page.
offsetnumber0Distance in px from the top of the scrolling area to the reading line, e.g. the height of a sticky header.
orientationWdsScrollspyOrientation'vertical'vertical (a table of contents) or horizontal (a bar of links above the content).
labelstring''Accessible name of the navigation (defaults to „On this page”).
activestring''id of the section being read (without #). Set by the scrollspy; read it or listen to wds-change.

Events

EventDescription
wds-changeCustomEvent<WdsScrollspyChangeDetail>The section being read changed.

Methods

MethodDescription
refresh()Re-reads the sections, e.g. after their content changed size.
scrollToSection(id: string)Scrolls a section (by id) to the reading line, marks it active and moves focus to it.

Slots

SlotDescription
(default)wds-scrollspy-item elements.

CSS parts (::part)

PartDescription
navThe <nav> around the items.

CSS custom properties

PropertyDescription
--wds-scrollspy-gapSpace between items (default 0 vertical, 4px horizontal).

Accessibility#

Screen reader#

The items are in a <nav> named by label (by default „On this page”). The active item has aria-current="location".

After a click focus moves to the section (it gets tabindex="-1" if it is not focusable), so a screen reader reads on from there and Tab continues inside it.

Scrolling is smooth unless the user prefers reduced motion.

Keyboard support#

KeyFunction
TabMoves focus through the items (each is a link).
EnterScrolls to the section of the focused item and moves focus to it.
Footer