A wrapper around
jQuery.animate({ scrollTop: offset })
to scroll the page to a specific element.
npm install --save @methodgrab/scroll-to
const scroll2 = require( '@methodgrab/scroll-to' );
$( '.btn' ).on( 'click', function( e ) {
scroll2( '.some-element' );
});
const scroll2 = require( '@methodgrab/scroll-to' );
$( '.btn' ).on( 'click', function( e ) {
scroll2( '.some-element', { duration: 1000, padding: 5 } )
.then( () => console.log( 'Done!' ) );
});
scroll2( selector, { duration, padding } )
Returns a Promise
that resolves when the scroll completes
String
The CSS selector of an element.
Number
(default: 250
)
The scroll duration in ms.
Number
(default: 50
)
An additional value, in px, to add to the scroll offset.
Useful to avoid scrolling to content under fixed headers etc.