$ npm install scroll-to-view
<script src="https://unpkg.com/scroll-to-view/dist/scroll-to-view.js"></script>
scrollToView('#header', 300);
name | desc | type | default | required |
---|---|---|---|---|
selector | element selector | string | - | ✔️ |
duration | animate time | number | 300 | - |
callback | callback function | function | - | - |
You can pass a callback or Promise
that will be called when all scrolling has been completed.
// callback
scrollToView('#header', 300, () => console.log('done'));
// promise
scrollToView('#header', 300).then(() => console.log('done'))
<= 1 KB