This enables smooth scrolling when a user clicks on anchor links or other in-page scrolling is triggered.
This is an opt-in behaviour that is activated by putting the vf-smooth-scroll
class on a parent element — a good place would be at <html class="vf-smooth-scroll">
(note: it probably won't work if you add it your <body>
element).
Note that as of Safari version 15.4 (released March 2022), CSS-based smooth scrolling is supported by Safari on Mac OS or iOS.
This component targets WCAG 2.1 AA accessibility.
Generally this improves accessibility by smooth scrolling between content, for some scenarios the behaviour may become distracting.
Note that smooth scrolling is disabled if a user has flagged prefers-reduced-motion
.
You can also read about the Visual Framework's approach to accessibility.
<div class="vf-smooth-scroll">
<p>
Scroll to:
<a href="#pageA">A</a>
<a href="#pageB">B</a>
<a href="#pageC">C</a>
</p>
<div class="vf-stack vf-stack--800" style="scroll-behavior: smooth; overflow-y: scroll; height: 100px; max-width: 350px;">
<article class="vf-card vf-card--brand vf-card--bordered" id="pageA">
<div class="vf-card__content | vf-stack vf-stack--400">
<h3 class="vf-card__heading">Item A</h3>
<p class="vf-card__subheading">With sub–heading</p>
</div>
</article>
<article class="vf-card vf-card--brand vf-card--bordered" id="pageB">
<div class="vf-card__content | vf-stack vf-stack--400">
<h3 class="vf-card__heading">Item B</h3>
<p class="vf-card__subheading">With sub–heading</p>
</div>
</article>
<article class="vf-card vf-card--brand vf-card--bordered" id="pageC">
<div class="vf-card__content | vf-stack vf-stack--400">
<h3 class="vf-card__heading">Item C</h3>
<p class="vf-card__subheading">With sub–heading</p>
</div>
</article>
</div>
</div>
This repository is distributed with [npm][https://www.npmjs.com/]. After [installing npm][https://www.npmjs.com/get-npm] and yarn, you can install vf-smooth-scroll
with this command.
$ yarn add --dev @visual-framework/vf-smooth-scroll
The style files included are written in Sass. If you're using a VF-core project, you can import it like this:
@import "@visual-framework/vf-smooth-scroll/vf-smooth-scroll.scss";
Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter
File system location: components/vf-smooth-scroll
Find an issue on this page? Propose a change or discuss it.