Socket
Socket
Sign inDemoInstall

lit-scroll

Package Overview
Dependencies
107
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lit-scroll

JS smooth scrolling library


Version published
Maintainers
1
Install size
3.63 MB
Created

Readme

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

FAQs

Last updated on 25 Apr 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc