scroll-to-element

Smooth scrolling to an element via selector or node reference

MIT 8 个版本
安装
npm install scroll-to-element
yarn add scroll-to-element
pnpm add scroll-to-element
bun add scroll-to-element
README

scroll-to-element

Smooth scrolls to element of the specified selector or element reference with optional offset, scroll-positon, easing, and duration. Takes into account document height for elements low on the page.

NPM

scrollToElement(selector, <options>)

Valid options:
offset : number

Add an additional offset to the final position. if > 0 then page is moved to the bottom otherwise the page is moved to the top.

align : string

Alignment of the element in the resulting viewport. Can be one of 'top', 'middle' or 'bottom'. Defaulting to 'top'.

ease : string

Easing function defaulting to "out-circ" (view ease for more)

duration : number

Animation duration defaulting to 1000

EXAMPLE

var scrollToElement = require('scroll-to-element');

scrollToElement('#id');

// with options
scrollToElement('.className', {
	offset: 0,
	ease: 'out-bounce',
	duration: 1500
});

// or if you already have a reference to the element
var elem = document.querySelector('.className');
scrollToElement(elem, {
	offset: 0,
	ease: 'out-bounce',
	duration: 1500
});

LICENSE

MIT

版本列表
2.0.3 2019-03-11
2.0.2 2018-08-25
2.0.1 2018-08-24
2.0.0 2016-02-04
1.1.0 2015-10-23
1.0.0 2015-08-14
0.0.2 2015-03-22
0.0.1 2015-03-15