js-scroll-to
v1.0.1
Published
A pure JS solution for scrolling to a specified element on command
Downloads
3
Readme
js-scroll-to
A pure JS solution for scrolling to a specified element on command.
About
The solution is made purely in JS with cross-framework and cross-browser compatibility in mind.
Parameters
All arguments should be encapsuled in a single object like the following
{
elementId: 'id',
behaviour: 'smooth',
axis: 'both'
}
elementId (*): The id of the element to which the view will scroll to.
axis (*) ('x' || 'y' || 'both') (default: 'none'): The axis on which to scroll.
xOffset (optional) (integer): The x axis offset.
yOffset (optional) (integer): The y axis offset.
behavior (optional) ('smooth' || 'auto') (default: 'smooth): The scroll animation behavior.
How to use
Just import it with the new ES6 syntax
import scrollTo from 'js-scroll-to'
or with the good old require
const scrollTo = require('js-scroll-to')
and then use it like any other function
scrollTo({
elementId: 'some-id',
yOffset: 10,
axis: 'y'
})