3.3.0 • Published 3 years ago

lit-scroll v3.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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: (stringnumberElement)Scroll to elementElement, opts: { native?: boolean })Scroll to an element (via selector, document top offset, or element reference)
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
3.3.0

3 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.1.5

4 years ago

3.2.0

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago