🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

lit-scroll

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lit-scroll

JS smooth scrolling library

3.3.0
latest
Source
npm
Version published
Weekly downloads
20
-79.17%
Maintainers
1
Weekly downloads
 
Created
Source

LitScroll

A lightweight (1.5kb gzipped) custom scroll implementation. Written in TypeScript.

Installation

Install it from NPM: npm i lit-scroll

Browser Support

The library uses a ResizeObserver (conditionally) to listen to scrollable element size change. In order to support dynamic scrollable container size change in Safari and IE, you should use ResizeObserver polyfill.

IMPORTANT: The library's default compilation target is ES6. If you need to support ES5 environments - consider transpiling it.

Usage

In your HTML:

<body>
    <div data-lit-scroll="wrapper">
        <div data-lit-scroll="container">
            <!-- Layout here -->
        </div>
    </div>
</body>

Note: wrapper element must be a descendant of <body>.

In your JS:

import createLitScroll from 'lit-scroll';

const scroll = createLitScroll({
    // defaults
    ease: 0.1,
    mobile: false,
});

Scroll sections

If your page is quite long, you can split your scroll container into scroll sections (via [data-lit-scroll="section"] attribute) to improve scrolling performance. This technique requires IntersectionObserver support. If none will be detected - [data-lit-scroll="section"] attribute will simply have no effect, nothing will break.

Syntax:

<body>
    <div data-lit-scroll="wrapper">
        <div data-lit-scroll="container">
            <div data-lit-scroll="section">
                <!-- Section content goes here -->
            </div>
            <div data-lit-scroll="section">
                <!-- Section content goes here -->
            </div>
            <!-- ...and so on -->
        </div>
    </div>
</body>

Options

OptionDefaultDescription
ease0.1Number. Configures linear interpolation "strength".
mobiletrueBoolean. Indicates whether or not library should take over native scroll on mobile devices

API

Methods

MethodParametersDescription
on(event: 'scroll', fn: Function)Add a scroll listener, which executes a specified function on every scroll change. Callback parameters: docScrollValue (current browser scroll value), scrollValue (current interpolated value), maxHeight (max scroll height), speed (positive if scrolling down, negative otherwise).
off(event: 'scroll', fn: Function)Remove a scroll listener
scrollTo(target: (stringnumber
getCurrentValuenoneGet current document scroll value
getCurrentLerpValuenoneGet current lerp scroll value
getSpeednoneGet current speed value
disablenoneDisable scrolling
enablenoneEnable scrolling
isEnablednoneGet scroll lock state. Returns boolean value. scrolling
destroynoneDestroy an instance

Keywords

custom scroll

FAQs

Package last updated on 25 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts