Skip to content

svnm/scroll-element

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scroll-element

Scroll to an element

npm version

Install

npm install scroll-element --save

Usage

Scroll-Element has 2 functions, scrollToElement scrolls to an element within a container div with overflow scroll. scrollWindowToElement just scrolls the window to the element. Check out the example for more info.

import { scrollToElement, scrollWindowToElement } from 'scroll-element'

/* scroll the window to your target element, duration and offset optional */
let targetElement = document.getElementById('my-item')
scrollWindowToElement(targetElement, 1000, -100)

/* scroll the overflow container element to your target element, duration and offset optional */
let containerElement = document.getElementById('my-container')
let targetElement = document.getElementById('my-item')
scrollToElement(containerElement, targetElement, 1000, -100)

Params

  • targetElement

The dom element to scroll to.

  • duration

Duration of time to scroll to the element in milliseconds. (Optional)

  • offset

An additional offset in pixels from the element being scrolled to. (Optional)

  • containerElement

The dom element to scroll, set this to overflow. (Only used for scrollWindowToElement function)

Development

npm install
npm run build
npm start

License

MIT

About

scroll to an element

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published