⚓️ Smoothly scroll to #anchors
- ... Scrolls to anchors
- Stops scrolling if the user scrolls
- Doesn't try to scroll past the end
It doesn't sound like much but it's actually really nice 😁
npm install anchor-scroller --save
const AnchorScroller = require('anchor-scroller');
new AnchorScroller();
You can pass the instance an options object to tweak it's behavior. The simplest options are class
and checkParent
.
new AnchorScroller({
class: 'scroll', // will make it only react on elements with the given class.
checkParent: true // will make it check the parent element, if the clicked element didn't match the criteria.
});
The more in-depth usage guide also has documentation on all options and methods.