A simplified, modern version of the original smooth scroll.
import animateScroll from './path/smooth-scroll.js';
const a = document.getElementById('link');
const destination = document.getElementById('destination');
a.addEventListener('click', e => {
animateScroll(destination, {speed: 5000});
e.preventDefault();
});This version, compared to the original, is:
- it's 50% smaller
- it's an ES6 module
- it uses
requestAnimationFrameinstead ofsetInterval - it doesn't include polyfills (closest, Object.assign / extend). If you really need them, include them yourself.
- it doesn't escape characters from hash (no CSS.escape)
- includes only two easing options (
easeOutCubic,easeInCubic) instead of 12. If you need a different one, pass a function as aneasingparam. - it doesn't track or measure your header. If you need it, measure it yourself and pass to the SmoothScroll via the
offsetparam (you can also pass a function here).
The code is available under the MIT License.