ScrollTo

Primitive #51

🔍 Problem it solves

Clicking a link (e.g., "Back to top" or anchor link) should smoothly scroll to a target element with an offset for fixed headers. Native scrollIntoView doesn't support offset or custom easing.

✅ Solution

scrollToElement(options) calculates target position (element offset minus offset amount) and performs smooth scrolling using requestAnimationFrame with configurable easing and duration. This demo uses an offset of 80px (to account for the fixed header) and 500ms duration.

🧩 Used by components

AnchorLink, BackToTopButton, TableOfContents, BreadcrumbScroll, WizardStepScroll

🎮 Interactive demo

Intro Section

Click the "Intro" button above to smoothly scroll here with an offset (so the section appears below the fixed header). Duration is 500ms.

Content area

Features Section

Scroll to this section using the "Features" button. The offset prevents the header from covering the title.

Content area

Pricing Section

Demonstrates smooth scrolling with custom easing (easeInOutCubic).

Content area

Contact Section

Even the last section scrolls correctly. The "Top" button uses scrollToTop to return to the top of the page.

Content area