A lightweight smooth scroll module with TypeScript support
npm install @cheshirecat/scroll2 --save
Default use in your main.js
import { scrollTo } from '@cheshirecat/scroll2'
...
const el = document.getElementById('anchor-1')
scrollTo(el)
...
You can pass an optional object for default duration and easing function; offset can be computed to match a fixed header element height for instance
...
const el = document.getElementById('anchor-2')
scrollTo(el, { easing: 'linear', duration: 600, offset: 32 })
...
By default, the plugin use a ease-in-out cubic function but you can pass one of the following parameters:
- 'linear'
- 'easeInQuad'
- 'easeOutQuad'
- 'easeInOutQuad'
- 'easeInCubic'
- 'easeOutCubic'
- 'easeInOutCubic'
- 'easeInQuart'
- 'easeOutQuart'
- 'easeInOutQuart'
- 'easeInQuint'
- 'easeOutQuint'
- 'easeInOutQuint'