Simple vanilla js library to smoothly scroll to anchors.
npm install @pxlrbt/smoothscroll
import Smoothscroll from '@pxlrbt/smoothscroll';
new Smoothscroll({
speed: 400,
elementSelector: 'a[href*="#"]',
useHash: true,
threshold: function () {
return document.querySelector('header').offsetHeight;
}
});
<a href="#section">Scroll to section</a>
...
<section id="section">...</section>