1.1.0 • Published 1 year ago

web-scroll v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
1 year ago

web-scroll

NPM downloads license

Browser History API with watch-state.

Installation

npm

npm i web-scroll

yarn

yarn add web-scroll

Using

Simple scrolling

import scroll from 'web-scroll'

scroll(0) // move to the top of the page

scroll('#root') // move to the element
scroll('.root') // move to the element

Callback for the scroll

scroll(0, () => alert('done'))
scroll('#root', () => alert('done'))

With options

scroll({
  position: 1, // scroll position of element's css selector
  timeInterval: 100, // the interval of scroll position checking for callback
  timeout: 30, // maximum count of position checking
  attempts: 3, // if the interface is freezing or smooth scrolling was interrupted, makes attempts to scroll it.
}, () => alert('done'))

Smooth scroll

Add this CSS style to have the smooth scroll on the page.

html {
  scroll-behavior: smooth;
}

Issues

If you find a bug, please file an issue on GitHub
issues


stars watchers