js-scroll-to

1.0.1 • Public • Published

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'
})

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i js-scroll-to

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

3.99 kB

Total Files

4

Last publish

Collaborators

  • jctubio