https://github.com/methodgrab/scroll-to
A wrapper around `jQuery.animate({ scrollTop: offset })` to scroll the page to a specific element
https://github.com/methodgrab/scroll-to
animation
Last synced: 3 months ago
JSON representation
A wrapper around `jQuery.animate({ scrollTop: offset })` to scroll the page to a specific element
- Host: GitHub
- URL: https://github.com/methodgrab/scroll-to
- Owner: MethodGrab
- Created: 2016-06-28T11:24:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T03:51:40.000Z (about 3 years ago)
- Last Synced: 2025-04-12T03:58:31.199Z (10 months ago)
- Topics: animation
- Language: HTML
- Size: 1.62 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scroll To [](https://travis-ci.org/MethodGrab/scroll-to) [](https://www.npmjs.com/package/@methodgrab/scroll-to)
> A wrapper around `jQuery.animate({ scrollTop: offset })` to scroll the page to a specific element.
## Install
```bash
npm install --save @methodgrab/scroll-to
```
## Examples:
```js
const scroll2 = require( '@methodgrab/scroll-to' );
$( '.btn' ).on( 'click', function( e ) {
scroll2( '.some-element' );
});
```
```js
const scroll2 = require( '@methodgrab/scroll-to' );
$( '.btn' ).on( 'click', function( e ) {
scroll2( '.some-element', { duration: 1000, padding: 5 } )
.then( () => console.log( 'Done!' ) );
});
```
## API
`scroll2( selector, { duration, padding } )`
Returns a `Promise` that resolves when the scroll completes
### `selector`
`String`
The CSS selector of an element.
### `options.duration`
`Number` (default: `250`)
The scroll duration in ms.
### `options.padding`
`Number` (default: `50`)
An additional value, in px, to add to the scroll offset.
Useful to avoid scrolling to content under fixed headers etc.