A tiny, ES6 JavaScript lib to handle smooth scrolling.
npm install smooth-scroller
See the full example.
import 'smooth-scroller';
<a href="#foo" data-smooth>Scroll Smoothly</a>
...some content...
<div id="foo"></div>
Custom events are fired on the element:
Event | Description |
---|---|
smoothscroll:start |
Smooth scroll starts |
smoothscroll:end |
Smooth scroll ends |
Smooth-scroller exposes two methods:
Enables smooth-scroller on the elements matched by selector
.
selector='[data-smooth]'
- {String} - Elements that will trigger smooth-scroll call once they're clicked
offset=0
- {Number} - Controls the distance (negative or positive) between the top border of the element and the top border of the window.
target
- {string|Element|NodeList} - Target element to scroll
hash
- {string|Element|NodeList} - DOM element ID to scroll
offset=0
- {Number} - Controls the distance (negative or positive) between the top border of the element and the top border of the window.
silent=false
- {Boolean} - If enabled, will generate a history.pushState
event