1. scroll-to-element
Smooth scrolling to an element via selector or node reference
scroll-to-element
Package: scroll-to-element
Created by: willhoag
Last modified: Sun, 26 Jun 2022 16:53:38 GMT
Version: 2.0.3
License: MIT
Downloads: 244,386
Repository: https://github.com/willhoag/scroll-to-element

Install

npm install scroll-to-element
yarn add scroll-to-element

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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code