Lenis
How smooth scroll should be
README
lenis
Introduction
This is our take on smooth scroll, lightweight, hard-working, smooth as butter scroll. See Demo.
Installation
JavaScript
using a package manager:
- ```bash
- npm i @studio-freight/lenis
- ```
- ```js
- import Lenis from '@studio-freight/lenis'
- ```
using scripts:
- ```html
- <script src="https://unpkg.com/@studio-freight/lenis@1.0.38/dist/lenis.min.js"></script>
- ```
Setup
Basic:
- ```js
- const lenis = new Lenis()
- lenis.on('scroll', (e) => {
- console.log(e)
- })
- function raf(time) {
- lenis.raf(time)
- requestAnimationFrame(raf)
- }
- requestAnimationFrame(raf)
- ```
GSAP ScrollTrigger:
- ```js
- const lenis = new Lenis()
- lenis.on('scroll', (e) => {
- console.log(e)
- })
- lenis.on('scroll', ScrollTrigger.update)
- gsap.ticker.add((time)=>{
- lenis.raf(time * 1000)
- })
- gsap.ticker.lagSmoothing(0)
- ```
React:
See documentation for react-lenis.
Instance settings
| Option | Type | Default | Description |
|---|---|---|---|
| |---|---|---|---| | |||
| `wrapper` | `HTMLElement, | `window` | The |
| `content` | `HTMLElement` | `document.documentElement` | The |
| `eventsTarget` | `HTMLElement, | `wrapper` | The |
| `lerp` | `number` | `0.1` | Linear |
| `duration` | `number` | `1.2` | The |
| `easing` | `function` | `(t) | The |
| `orientation` | `string` | `vertical` | The |
| `gestureOrientation` | `string` | `vertical` | The |
| `smoothWheel` | `boolean` | `true` | Whether |
| `syncTouch` | `boolean` | `false` | Mimic |
| `syncTouchLerp` | `number` | `0.075` | Lerp |
| `touchInertiaMultiplier` | `number` | `35` | Manage |
| `wheelMultiplier` | `number` | `1` | The |
| `touchMultiplier` | `number` | `1` | The |
| `normalizeWheel` | `boolean` | `false` | Normalize |
| `infinite` | `boolean` | `false` | Enable |
| `autoResize` | `boolean` | `true` | Resize |
探客时代
