web-scroll
v1.1.0
Published
Scroll the page with css smooth scroll
Downloads
9
Readme
web-scroll
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