scrollto-element

1.0.4 • Public • Published

scrollto-element

npm version Standard - JavaScript Style Guide

A simple animated scroll to element function.

Install

npm install scrollto-element --save
// or
yarn add scrollto-element

Usage

const scrolltoElement = require('scrollto-element')
// or ES2015+
import scrolltoElement from 'scrollto-element'

Example

import scrolltoElement from 'scrollto-element'
 
scrolltoElement(document.querySelector('#foobar'))
scrolltoElement(element, 300)
 
// advanced
scrolltoElement({
  element: document.querySelector('#foobar'),
  offset: -100, // default is 0
  bezier: [0.19, 1, 0.22, 1], // default is [0.19, 1, 0.22, 1]
  duration: 3000, // default is 100
  then () {
    console.log('Finished~')
  }
})

offset means scroll to (target element + offset).
When offset is a positive number, view will scroll through the target.
When offset is a negative number, view will scroll to near the target.

See also

License

MIT

Package Sidebar

Install

npm i scrollto-element

Weekly Downloads

21

Version

1.0.4

License

MIT

Last publish

Collaborators

  • blade254353074