scrollto-element
v1.0.4
Published
A simple animated scroll to element function.
Downloads
122
Maintainers
Readme
scrollto-element
A simple animated scroll to element function.
- Using requestAnimationFrame
- Only require bezier-easing and raf
Install
npm install scrollto-element --save
// or
yarn add scrollto-element
Usage
const scrolltoElement = require('scrollto-element')
// or ES2015+
import scrolltoElement from 'scrollto-element'
Example
import scrolltoElement from 'scrollto-element'
scrolltoElement(document.querySelector('#foobar'))
scrolltoElement(element, 300)
// advanced
scrolltoElement({
element: document.querySelector('#foobar'),
offset: -100, // default is 0
bezier: [0.19, 1, 0.22, 1], // default is [0.19, 1, 0.22, 1]
duration: 3000, // default is 100
then () {
console.log('Finished~')
}
})
offset means scroll to (target element + offset).
When offset is a positive number, view will scroll through the target.
When offset is a negative number, view will scroll to near the target.
See also
License
MIT