lenis 1.1.21-dev.0 → 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,329 +1,354 @@
1
- [![LENIS](https://assets.darkroom.engineering/lenis/header.png)](https://github.com/darkroomengineering/lenis)
2
-
3
- [![npm](https://img.shields.io/npm/v/lenis?colorA=000000&colorB=ff98a2
4
- )](https://www.npmjs.com/package/lenis)
5
- [![downloads](https://img.shields.io/npm/dm/lenis?colorA=000000&colorB=ff98a2
6
- )](https://www.npmjs.com/package/lenis)
7
- [![size](https://img.shields.io/bundlephobia/minzip/lenis?label=size&colorA=000000&colorB=ff98a2)](https://bundlephobia.com/package/lenis)
8
-
9
- ## Introduction
10
-
11
- Lenis ("smooth" in latin) is a lightweight, robust, and performant smooth scroll library. It's designed by [@darkroom.engineering](https://twitter.com/darkroomdevs) to be simple to use and easy to integrate into your projects. It's built with performance in mind and is optimized for modern browsers. It's perfect for creating smooth scrolling experiences on your website such as webgl scroll synching, parallax effects and much more, see [ Demo](https://lenis.darkroom.engineering/) and [Showcase](#lenis-in-use).
12
-
13
- Read our [Manifesto](https://github.com/darkroomengineering/lenis/blob/main/MANIFESTO.md) to learn more about the inspiration behind Lenis.
14
-
15
- <br/>
16
-
17
- ## Sponsors
18
-
19
- If you like Lenis, please consider [becoming a sponsor](https://github.com/sponsors/darkroomengineering). Your support helps us to smooth the web one library at a time.
20
-
21
- #### They make it possible:
22
- [![Scott Sunarto](https://avatars.githubusercontent.com/u/4402697?s=80&v=4)](https://smsunarto.com/) [![cachet.studio](https://avatars.githubusercontent.com/u/75880965?s=80&v=4)](https://www.cachet.studio/) [![Mario Sanchez Maselli](https://avatars.githubusercontent.com/u/1336977?s=80&v=4)](https://non-linear.studio/)
23
-
24
- <br>
25
-
26
- ## Packages
27
-
28
- - [lenis](https://github.com/darkroomengineering/lenis/blob/main/README.md)
29
- - [lenis/react](https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md)
30
- - [lenis/snap](https://github.com/darkroomengineering/lenis/tree/main/packages/snap/README.md)
31
-
32
-
33
- <br>
34
-
35
- ## Installation
36
-
37
- ### JavaScript
38
-
39
- using a package manager:
40
-
41
- ```bash
42
- npm i lenis
43
- ```
44
- ```js
45
- import Lenis from 'lenis'
46
- ```
47
-
48
- <br/>
49
-
50
- using scripts:
51
-
52
- ```html
53
- <script src="https://unpkg.com/lenis@1.1.20/dist/lenis.min.js"></script>
54
- ```
55
-
56
-
57
- <br>
58
-
59
- ## Setup
60
-
61
- ### Basic:
62
-
63
- ```js
64
- // Initialize Lenis
65
- const lenis = new Lenis({
66
- autoRaf: true,
67
- });
68
-
69
- // Listen for the scroll event and log the event data
70
- lenis.on('scroll', (e) => {
71
- console.log(e);
72
- });
73
- ```
74
-
75
- ### Custom raf loop:
76
-
77
- ```js
78
- // Initialize Lenis
79
- const lenis = new Lenis();
80
-
81
- // Use requestAnimationFrame to continuously update the scroll
82
- function raf(time) {
83
- lenis.raf(time);
84
- requestAnimationFrame(raf);
85
- }
86
-
87
- requestAnimationFrame(raf);
88
- ```
89
-
90
- #### Recommended CSS:
91
-
92
- import stylesheet
93
- ```js
94
- import 'lenis/dist/lenis.css'
95
- ```
96
-
97
- or link the CSS file:
98
-
99
- ```html
100
- <link rel="stylesheet" href="https://unpkg.com/lenis@1.1.20/dist/lenis.css">
101
- ```
102
-
103
- or add it manually:
104
-
105
- [See lenis.css stylesheet](./packages/core/lenis.css)
106
-
107
- ### GSAP ScrollTrigger:
108
- ```js
109
- // Initialize a new Lenis instance for smooth scrolling
110
- const lenis = new Lenis();
111
-
112
- // Synchronize Lenis scrolling with GSAP's ScrollTrigger plugin
113
- lenis.on('scroll', ScrollTrigger.update);
114
-
115
- // Add Lenis's requestAnimationFrame (raf) method to GSAP's ticker
116
- // This ensures Lenis's smooth scroll animation updates on each GSAP tick
117
- gsap.ticker.add((time) => {
118
- lenis.raf(time * 1000); // Convert time from seconds to milliseconds
119
- });
120
-
121
- // Disable lag smoothing in GSAP to prevent any delay in scroll animations
122
- gsap.ticker.lagSmoothing(0);
123
-
124
- ```
125
-
126
- ### React:
127
- [See documentation for lenis/react](https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md).
128
-
129
-
130
-
131
-
132
- <br/>
133
-
134
-
135
- ## Instance settings
136
-
137
- | Option | Type | Default | Description |
138
- |--------------------------|-----------------------------|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
139
- | `wrapper` | `HTMLElement, Window` | `window` | The element that will be used as the scroll container |
140
- | `content` | `HTMLElement` | `document.documentElement` | The element that contains the content that will be scrolled, usually `wrapper`'s direct child |
141
- | `eventsTarget` | `HTMLElement, Window` | `wrapper` | The element that will listen to `wheel` and `touch` events |
142
- | `smoothWheel` | `boolean` | `true` | Smooth the scroll initiated by `wheel` events |
143
- | `lerp` | `number` | `0.1` | Linear interpolation (lerp) intensity (between 0 and 1) |
144
- | `duration` | `number` | `1.2` | The duration of scroll animation (in seconds). Useless if lerp defined |
145
- | `easing` | `function` | `(t) => Math.min(1, 1.001 - Math.pow(2, -10 * t))` | The easing function to use for the scroll animation, our default is custom but you can pick one from [Easings.net](https://easings.net/en). Useless if lerp defined |
146
- | `orientation` | `string` | `vertical` | The orientation of the scrolling. Can be `vertical` or `horizontal` |
147
- | `gestureOrientation` | `string` | `vertical` | The orientation of the gestures. Can be `vertical`, `horizontal` or `both` |
148
- | `syncTouch` | `boolean` | `false` | Mimic touch device scroll while allowing scroll sync (can be unstable on iOS<16) |
149
- | `syncTouchLerp` | `number` | `0.075` | Lerp applied during `syncTouch` inertia |
150
- | `touchInertiaMultiplier` | `number` | `35` | Manage the strength of syncTouch inertia |
151
- | `wheelMultiplier` | `number` | `1` | The multiplier to use for mouse wheel events |
152
- | `touchMultiplier` | `number` | `1` | The multiplier to use for touch events |
153
- | `infinite` | `boolean` | `false` | Enable infinite scrolling! `syncTouch: true` is required on touch devices. ([See example](https://codepen.io/ClementRoche/pen/OJqBLod)) |
154
- | `autoResize` | `boolean` | `true` | Resize instance automatically based on `ResizeObserver`. If `false` you must resize manually using `.resize()` |
155
- | `prevent` | `function` | `undefined` | Manually prevent scroll to be smoothed based on elements traversed by events. If `true` is returned, it will prevent the scroll to be smoothed. Example: `(node) => node.classList.contains('cookie-modal')` |
156
- | `virtualScroll` | `function` | `undefined` | Manually modify the events before they get consumed. If `false` is returned, the scroll will not be smoothed. Examples: `(e) => { e.deltaY /= 2 }` (to slow down vertical scroll) or `({ event }) => !event.shiftKey` (to prevent scroll to be smoothed if shift key is pressed) |
157
- | `overscroll` | `boolean` | `true` | Wether or not to enable overscroll on a nested Lenis instance, similar to CSS overscroll-behavior (https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior) |
158
- | `autoRaf` | `boolean` | `false` | Wether or not to automatically run `requestAnimationFrame` loop |
159
- | `anchors` | `boolean | ScrollToOptions` | `false` | Wether or not to enable anchor links. If `true` is passed, it will enable anchor links with default options. If `ScrollToOptions` is passed, it will enable anchor links with the given options. |
160
- <br/>
161
-
162
- <!-- `target`: goal to reach
163
- - `number`: value to scroll in pixels
164
- - `string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)
165
- - `HTMLElement`: DOM element
166
-
167
- <br/>
168
-
169
- `options`:
170
- - `offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)
171
- - `lerp`(`number`): animation lerp intensity
172
- - `duration`(`number`): animation duration (in seconds)
173
- - `easing`(`function`): animation easing
174
- - `immediate`(`boolean`): ignore duration, easing and lerp
175
- - `lock`(`boolean`): whether or not to prevent user from scrolling until target reached
176
- - `onComplete`(`function`): called when target is reached -->
177
-
178
- ## Instance Props
179
-
180
- | Property | Type | Description |
181
- |-------------------------|-------------------|----------------------------------------------------------------------------|
182
- | `animatedScroll` | `number` | Current scroll value |
183
- | `dimensions` | `object` | Dimensions instance |
184
- | `direction` | `number` | `1`: scrolling up, `-1`: scrolling down |
185
- | `emitter` | `object` | Emitter instance |
186
- | `options` | `object` | Instance options |
187
- | `targetScroll` | `number` | Target scroll value |
188
- | `time` | `number` | Time elapsed since instance creation |
189
- | `actualScroll` | `number` | Current scroll value registered by the browser |
190
- | `lastVelocity` | `number` | last scroll velocity |
191
- | `velocity` | `number` | Current scroll velocity |
192
- | `isHorizontal` (getter) | `boolean` | Whether or not the instance is horizontal |
193
- | `isScrolling` (getter) | `boolean, string` | Whether or not the scroll is being animated, `smooth`, `native` or `false` |
194
- | `isStopped` (getter) | `boolean` | Whether or not the user should be able to scroll |
195
- | `limit` (getter) | `number` | Maximum scroll value |
196
- | `progress` (getter) | `number` | Scroll progress from `0` to `1` |
197
- | `rootElement` (getter) | `HTMLElement` | Element on which Lenis is instanced |
198
- | `scroll` (getter) | `number` | Current scroll value (handles infinite scroll if activated) |
199
- | `className` (getter) | `string` | `rootElement` className |
200
-
201
- <br/>
202
-
203
- ## Instance Methods
204
-
205
- | Method | Description | Arguments |
206
- |-----------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
207
- | `raf(time)` | Must be called every frame for internal usage. | `time`: in ms |
208
- | `scrollTo(target, options)` | Scroll to target. | `target`: goal to reach<ul><li>`number`: value to scroll in pixels</li><li>`string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)</li><li>`HTMLElement`: DOM element</li></ul>`options`<ul><li>`offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)</li><li>`lerp`(`number`): animation lerp intensity</li><li>`duration`(`number`): animation duration (in seconds)</li><li>`easing`(`function`): animation easing</li><li>`immediate`(`boolean`): ignore duration, easing and lerp</li><li>`lock`(`boolean`): whether or not to prevent the user from scrolling until the target is reached</li><li>`force`(`boolean`): reach target even if instance is stopped</li><li>`onComplete`(`function`): called when the target is reached</li><li>`userData`(`object`): this object will be forwarded through `scroll` events</li></ul> |
209
- | `on(id, function)` | `id` can be any of the following [instance events](#instance-events) to listen. | |
210
- | `stop()` | Pauses the scroll | |
211
- | `start()` | Resumes the scroll | |
212
- | `resize()` | Compute internal sizes, it has to be used if `autoResize` option is `false`. | |
213
- | `destroy()` | Destroys the instance and removes all events. | |
214
-
215
-
216
-
217
- ## Instance Events
218
-
219
- | Event | Callback Arguments |
220
- |------------------|---------------------------|
221
- | `scroll` | Lenis instance |
222
- | `virtual-scroll` | `{deltaX, deltaY, event}` |
223
-
224
-
225
- <br/>
226
-
227
- ## Considerations
228
-
229
- ### Nested scroll
230
-
231
- #### Using Javascript
232
-
233
- ```html
234
- <div id="modal">scrollable content</div>
235
- ```
236
-
237
- ```js
238
- const lenis = new Lenis({
239
- prevent: (node) => node.id === 'modal',
240
- })
241
- ```
242
-
243
- [See example](https://codepen.io/ClementRoche/pen/emONGYN)
244
-
245
- #### Using HTML
246
-
247
- ```html
248
- <div data-lenis-prevent>scrollable content</div>
249
- ```
250
-
251
- [See example](https://codepen.io/ClementRoche/pen/PoLdjpw)
252
-
253
- prevent wheel events only
254
-
255
- ```html
256
- <div data-lenis-prevent-wheel>scrollable content</div>
257
- ```
258
-
259
- prevent touch events only
260
-
261
- ```html
262
- <div data-lenis-prevent-touch>scrollable content</div>
263
- ```
264
-
265
-
266
-
267
- ### Anchor links
268
- By default Lenis will prevent anchor links click while scrolling, to fix that you must set `anchors: true`.
269
-
270
- ```js
271
- new Lenis({
272
- anchors: true
273
- })
274
- ```
275
-
276
- You can also use `scrollTo` options.
277
- ```js
278
- new Lenis({
279
- anchors: {
280
- offset: 100,
281
- onComplete: ()=>{
282
- console.log('scrolled to anchor')
283
- }
284
- }
285
- })
286
- ```
287
-
288
- <br>
289
-
290
- ## Limitations
291
-
292
- - no support for CSS scroll-snap, you must use ([lenis/snap](https://github.com/darkroomengineering/lenis/tree/main/packages/snap/README.md))
293
- - capped to 60fps on Safari ([source](https://bugs.webkit.org/show_bug.cgi?id=173434)) and 30fps on low power mode
294
- - smooth scroll will stop working over iframe since they don't forward wheel events
295
- - position fixed seems to lag on MacOS Safari pre-M1 ([source](https://github.com/darkroomengineering/lenis/issues/103))
296
- - touch events may behave unexpectedly when `syncTouch` is enabled on iOS < 16
297
- - nested scroll containers require proper configuration to work correctly
298
-
299
- <br>
300
-
301
- ## Tutorials
302
-
303
- - [Scroll Animation Ideas for Image Grids](https://tympanus.net/Development/ScrollAnimationsGrid/) by [Codrops](https://tympanus.net/codrops)
304
- - [How to Animate SVG Shapes on Scroll](https://tympanus.net/codrops/2022/06/08/how-to-animate-svg-shapes-on-scroll) by [Codrops](https://tympanus.net/codrops)
305
- - [The BEST smooth scrolling library for your Webflow website! (Lenis)](https://www.youtube.com/watch?v=VtCqTLRRMII) by [Diego Toda de Oliveira](https://www.diegoliv.works/)
306
- - [Easy smooth scroll in @Webflow with Lenis + GSAP ScrollTrigger tutorial](https://www.youtube.com/watch?v=gRKuzQTXq74) by [También Studio](https://www.tambien.studio/)
307
-
308
- <br>
309
-
310
- ## Plugins
311
-
312
- - [r3f-scroll-rig](https://github.com/14islands/r3f-scroll-rig) by [14islands](https://14islands.com/)
313
- - [locomotive-scroll](https://github.com/locomotivemtl/locomotive-scroll) by [Locomotive](https://locomotive.ca/)
314
-
315
- <br>
316
-
317
- ## Lenis in use
318
-
319
- - [DeSo](https://deso.com) by [Studio Freight](https://www.studiofreight.com/)
320
- - [Sculpting Harmony](https://gehry.getty.edu/) by [Resn](https://resn.co.nz/)
321
- - [Superpower](https://superpower.com/)
322
- - [Daylight Computer](https://daylightcomputer.com/) by [Basement Studio](https://basement.studio/)
323
- - [Lifeworld by Olafur Eliasson](https://lifeworld.wetransfer.com/) by Nicolas Garnier, Simon Riisnæs Dagfinrud, Lumír Španihel, Everton Guilherme, Diana Alcausin, Cristiana Sousa
324
-
325
- <br/>
326
-
327
- ## License
328
-
329
- MIT © [darkroom.engineering](https://github.com/darkroomengineering)
1
+ [![LENIS](https://assets.darkroom.engineering/lenis/banner.gif)](https://github.com/darkroomengineering/lenis)
2
+
3
+ [![npm](https://img.shields.io/npm/v/lenis?colorA=E30613&colorB=000000
4
+ )](https://www.npmjs.com/package/lenis)
5
+ [![downloads](https://img.shields.io/npm/dm/lenis?colorA=E30613&colorB=000000
6
+ )](https://www.npmjs.com/package/lenis)
7
+ [![size](https://img.shields.io/bundlephobia/minzip/lenis?label=size&colorA=E30613&colorB=000000)](https://bundlephobia.com/package/lenis)
8
+
9
+ ## Introduction
10
+
11
+ Lenis ("smooth" in latin) is a lightweight, robust, and performant smooth scroll library. It's designed by [@darkroom.engineering](https://twitter.com/darkroomdevs) to be simple to use and easy to integrate into your projects. It's built with performance in mind and is optimized for modern browsers. It's perfect for creating smooth scrolling experiences on your website such as webgl scroll synching, parallax effects and much more, see [ Demo](https://lenis.darkroom.engineering/) and [Showcase](#lenis-in-use).
12
+
13
+ Read our [Manifesto](https://github.com/darkroomengineering/lenis/blob/main/MANIFESTO.md) to learn more about the inspiration behind Lenis.
14
+
15
+ <br/>
16
+
17
+ - [Sponsors](#sponsors)
18
+ - [Packages](#packages)
19
+ - [Installation](#installation)
20
+ - [Setup](#setup)
21
+ - [Settings](#settings)
22
+ - [Properties](#properties)
23
+ - [Methods](#methods)
24
+ - [Events](#events)
25
+ - [Considerations](#considerations)
26
+ - [Limitations](#limitations)
27
+ - [Troubleshooting](#troubleshooting)
28
+ - [Tutorials](#tutorials)
29
+ - [Plugins](#plugins)
30
+ - [Lenis is Use](#lenis-in-use)
31
+ - [License](#license)
32
+
33
+ <br/>
34
+
35
+ ## Sponsors
36
+
37
+ If you like Lenis, please consider [becoming a sponsor](https://github.com/sponsors/darkroomengineering). Your support helps us to smooth the web one library at a time.
38
+
39
+ [![Scott Sunarto](https://avatars.githubusercontent.com/u/4402697?s=80&v=4)](https://smsunarto.com/) [![Iron Velvet](https://avatars.githubusercontent.com/u/58460073?s=80&v=4)](https://www.ironvelvet.studio/) [![cachet.studio](https://avatars.githubusercontent.com/u/75880965?s=80&v=4)](https://www.cachet.studio/) [![Mario Sanchez Maselli](https://avatars.githubusercontent.com/u/1336977?s=80&v=4)](https://non-linear.studio/) [![Federico Valla](https://avatars.githubusercontent.com/u/38297526?s=80&v=4)](https://www.federic.ooo/)
40
+
41
+ <br>
42
+
43
+ ## Packages
44
+
45
+ - [lenis](https://github.com/darkroomengineering/lenis/blob/main/README.md)
46
+ - [lenis/react](https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md)
47
+ - [lenis/vue](https://github.com/darkroomengineering/lenis/tree/main/packages/vue/README.md)
48
+ - [lenis/snap](https://github.com/darkroomengineering/lenis/tree/main/packages/snap/README.md)
49
+
50
+
51
+ <br>
52
+
53
+ ## Installation
54
+
55
+ using a package manager:
56
+
57
+ ```bash
58
+ npm i lenis
59
+ ```
60
+ ```js
61
+ import Lenis from 'lenis'
62
+ ```
63
+
64
+ <br/>
65
+
66
+ using scripts:
67
+
68
+ ```html
69
+ <script src="https://unpkg.com/lenis@1.1.21/dist/lenis.min.js"></script>
70
+ ```
71
+
72
+
73
+ <br>
74
+
75
+ ## Setup
76
+
77
+ ### Basic:
78
+
79
+ ```js
80
+ // Initialize Lenis
81
+ const lenis = new Lenis({
82
+ autoRaf: true,
83
+ });
84
+
85
+ // Listen for the scroll event and log the event data
86
+ lenis.on('scroll', (e) => {
87
+ console.log(e);
88
+ });
89
+ ```
90
+
91
+ ### Custom raf loop:
92
+
93
+ ```js
94
+ // Initialize Lenis
95
+ const lenis = new Lenis();
96
+
97
+ // Use requestAnimationFrame to continuously update the scroll
98
+ function raf(time) {
99
+ lenis.raf(time);
100
+ requestAnimationFrame(raf);
101
+ }
102
+
103
+ requestAnimationFrame(raf);
104
+ ```
105
+
106
+ ### Recommended CSS:
107
+
108
+ import stylesheet
109
+ ```js
110
+ import 'lenis/dist/lenis.css'
111
+ ```
112
+
113
+ or link the CSS file:
114
+
115
+ ```html
116
+ <link rel="stylesheet" href="https://unpkg.com/lenis@1.1.21/dist/lenis.css">
117
+ ```
118
+
119
+ or add it manually:
120
+
121
+ [See lenis.css stylesheet](./packages/core/lenis.css)
122
+
123
+ ### GSAP ScrollTrigger:
124
+ ```js
125
+ // Initialize a new Lenis instance for smooth scrolling
126
+ const lenis = new Lenis();
127
+
128
+ // Synchronize Lenis scrolling with GSAP's ScrollTrigger plugin
129
+ lenis.on('scroll', ScrollTrigger.update);
130
+
131
+ // Add Lenis's requestAnimationFrame (raf) method to GSAP's ticker
132
+ // This ensures Lenis's smooth scroll animation updates on each GSAP tick
133
+ gsap.ticker.add((time) => {
134
+ lenis.raf(time * 1000); // Convert time from seconds to milliseconds
135
+ });
136
+
137
+ // Disable lag smoothing in GSAP to prevent any delay in scroll animations
138
+ gsap.ticker.lagSmoothing(0);
139
+
140
+ ```
141
+
142
+ ### React:
143
+ [See documentation for lenis/react](https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md).
144
+
145
+
146
+
147
+
148
+ <br/>
149
+
150
+
151
+ ## Settings
152
+
153
+ | Option | Type | Default | Description |
154
+ |--------------------------|-----------------------------|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
155
+ | `wrapper` | `HTMLElement, Window` | `window` | The element that will be used as the scroll container |
156
+ | `content` | `HTMLElement` | `document.documentElement` | The element that contains the content that will be scrolled, usually `wrapper`'s direct child |
157
+ | `eventsTarget` | `HTMLElement, Window` | `wrapper` | The element that will listen to `wheel` and `touch` events |
158
+ | `smoothWheel` | `boolean` | `true` | Smooth the scroll initiated by `wheel` events |
159
+ | `lerp` | `number` | `0.1` | Linear interpolation (lerp) intensity (between 0 and 1) |
160
+ | `duration` | `number` | `1.2` | The duration of scroll animation (in seconds). Useless if lerp defined |
161
+ | `easing` | `function` | `(t) => Math.min(1, 1.001 - Math.pow(2, -10 * t))` | The easing function to use for the scroll animation, our default is custom but you can pick one from [Easings.net](https://easings.net/en). Useless if lerp defined |
162
+ | `orientation` | `string` | `vertical` | The orientation of the scrolling. Can be `vertical` or `horizontal` |
163
+ | `gestureOrientation` | `string` | `vertical` | The orientation of the gestures. Can be `vertical`, `horizontal` or `both` |
164
+ | `syncTouch` | `boolean` | `false` | Mimic touch device scroll while allowing scroll sync (can be unstable on iOS<16) |
165
+ | `syncTouchLerp` | `number` | `0.075` | Lerp applied during `syncTouch` inertia |
166
+ | `touchInertiaMultiplier` | `number` | `35` | Manage the strength of syncTouch inertia |
167
+ | `wheelMultiplier` | `number` | `1` | The multiplier to use for mouse wheel events |
168
+ | `touchMultiplier` | `number` | `1` | The multiplier to use for touch events |
169
+ | `infinite` | `boolean` | `false` | Enable infinite scrolling! `syncTouch: true` is required on touch devices. ([See example](https://codepen.io/ClementRoche/pen/OJqBLod)) |
170
+ | `autoResize` | `boolean` | `true` | Resize instance automatically based on `ResizeObserver`. If `false` you must resize manually using `.resize()` |
171
+ | `prevent` | `function` | `undefined` | Manually prevent scroll to be smoothed based on elements traversed by events. If `true` is returned, it will prevent the scroll to be smoothed. Example: `(node) => node.classList.contains('cookie-modal')` |
172
+ | `virtualScroll` | `function` | `undefined` | Manually modify the events before they get consumed. If `false` is returned, the scroll will not be smoothed. Examples: `(e) => { e.deltaY /= 2 }` (to slow down vertical scroll) or `({ event }) => !event.shiftKey` (to prevent scroll to be smoothed if shift key is pressed) |
173
+ | `overscroll` | `boolean` | `true` | Wether or not to enable overscroll on a nested Lenis instance, similar to CSS overscroll-behavior (https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior) |
174
+ | `autoRaf` | `boolean` | `false` | Wether or not to automatically run `requestAnimationFrame` loop |
175
+ | `anchors` | `boolean | ScrollToOptions` | `false` | Wether or not to enable anchor links. If `true` is passed, it will enable anchor links with default options. If `ScrollToOptions` is passed, it will enable anchor links with the given options. |
176
+ <br/>
177
+
178
+ <!-- `target`: goal to reach
179
+ - `number`: value to scroll in pixels
180
+ - `string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)
181
+ - `HTMLElement`: DOM element
182
+
183
+ <br/>
184
+
185
+ `options`:
186
+ - `offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)
187
+ - `lerp`(`number`): animation lerp intensity
188
+ - `duration`(`number`): animation duration (in seconds)
189
+ - `easing`(`function`): animation easing
190
+ - `immediate`(`boolean`): ignore duration, easing and lerp
191
+ - `lock`(`boolean`): whether or not to prevent user from scrolling until target reached
192
+ - `onComplete`(`function`): called when target is reached -->
193
+
194
+ ## Properties
195
+
196
+ | Property | Type | Description |
197
+ |-------------------------|-------------------|----------------------------------------------------------------------------|
198
+ | `animatedScroll` | `number` | Current scroll value |
199
+ | `dimensions` | `object` | Dimensions instance |
200
+ | `direction` | `number` | `1`: scrolling up, `-1`: scrolling down |
201
+ | `emitter` | `object` | Emitter instance |
202
+ | `options` | `object` | Instance options |
203
+ | `targetScroll` | `number` | Target scroll value |
204
+ | `time` | `number` | Time elapsed since instance creation |
205
+ | `actualScroll` | `number` | Current scroll value registered by the browser |
206
+ | `lastVelocity` | `number` | last scroll velocity |
207
+ | `velocity` | `number` | Current scroll velocity |
208
+ | `isHorizontal` (getter) | `boolean` | Whether or not the instance is horizontal |
209
+ | `isScrolling` (getter) | `boolean, string` | Whether or not the scroll is being animated, `smooth`, `native` or `false` |
210
+ | `isStopped` (getter) | `boolean` | Whether or not the user should be able to scroll |
211
+ | `limit` (getter) | `number` | Maximum scroll value |
212
+ | `progress` (getter) | `number` | Scroll progress from `0` to `1` |
213
+ | `rootElement` (getter) | `HTMLElement` | Element on which Lenis is instanced |
214
+ | `scroll` (getter) | `number` | Current scroll value (handles infinite scroll if activated) |
215
+ | `className` (getter) | `string` | `rootElement` className |
216
+
217
+ <br/>
218
+
219
+ ## Methods
220
+
221
+ | Method | Description | Arguments |
222
+ |-----------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
223
+ | `raf(time)` | Must be called every frame for internal usage. | `time`: in ms |
224
+ | `scrollTo(target, options)` | Scroll to target. | `target`: goal to reach<ul><li>`number`: value to scroll in pixels</li><li>`string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)</li><li>`HTMLElement`: DOM element</li></ul>`options`<ul><li>`offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)</li><li>`lerp`(`number`): animation lerp intensity</li><li>`duration`(`number`): animation duration (in seconds)</li><li>`easing`(`function`): animation easing</li><li>`immediate`(`boolean`): ignore duration, easing and lerp</li><li>`lock`(`boolean`): whether or not to prevent the user from scrolling until the target is reached</li><li>`force`(`boolean`): reach target even if instance is stopped</li><li>`onComplete`(`function`): called when the target is reached</li><li>`userData`(`object`): this object will be forwarded through `scroll` events</li></ul> |
225
+ | `on(id, function)` | `id` can be any of the following [instance events](#instance-events) to listen. | |
226
+ | `stop()` | Pauses the scroll | |
227
+ | `start()` | Resumes the scroll | |
228
+ | `resize()` | Compute internal sizes, it has to be used if `autoResize` option is `false`. | |
229
+ | `destroy()` | Destroys the instance and removes all events. | |
230
+
231
+
232
+
233
+ ## Events
234
+
235
+ | Event | Callback Arguments |
236
+ |------------------|---------------------------|
237
+ | `scroll` | Lenis instance |
238
+ | `virtual-scroll` | `{deltaX, deltaY, event}` |
239
+
240
+
241
+ <br/>
242
+
243
+ ## Considerations
244
+
245
+ ### Nested scroll
246
+
247
+ #### Using Javascript
248
+
249
+ ```html
250
+ <div id="modal">scrollable content</div>
251
+ ```
252
+
253
+ ```js
254
+ const lenis = new Lenis({
255
+ prevent: (node) => node.id === 'modal',
256
+ })
257
+ ```
258
+
259
+ [See example](https://codepen.io/ClementRoche/pen/emONGYN)
260
+
261
+ #### Using HTML
262
+
263
+ ```html
264
+ <div data-lenis-prevent>scrollable content</div>
265
+ ```
266
+
267
+ [See example](https://codepen.io/ClementRoche/pen/PoLdjpw)
268
+
269
+ prevent wheel events only
270
+
271
+ ```html
272
+ <div data-lenis-prevent-wheel>scrollable content</div>
273
+ ```
274
+
275
+ prevent touch events only
276
+
277
+ ```html
278
+ <div data-lenis-prevent-touch>scrollable content</div>
279
+ ```
280
+
281
+
282
+
283
+ ### Anchor links
284
+ By default Lenis will prevent anchor links click while scrolling, to fix that you must set `anchors: true`.
285
+
286
+ ```js
287
+ new Lenis({
288
+ anchors: true
289
+ })
290
+ ```
291
+
292
+ You can also use `scrollTo` options.
293
+ ```js
294
+ new Lenis({
295
+ anchors: {
296
+ offset: 100,
297
+ onComplete: ()=>{
298
+ console.log('scrolled to anchor')
299
+ }
300
+ }
301
+ })
302
+ ```
303
+
304
+ <br>
305
+
306
+ ## Limitations
307
+
308
+ - no support for CSS scroll-snap, you must use ([lenis/snap](https://github.com/darkroomengineering/lenis/tree/main/packages/snap/README.md))
309
+ - capped to 60fps on Safari ([source](https://bugs.webkit.org/show_bug.cgi?id=173434)) and 30fps on low power mode
310
+ - smooth scroll will stop working over iframe since they don't forward wheel events
311
+ - position fixed seems to lag on MacOS Safari pre-M1 ([source](https://github.com/darkroomengineering/lenis/issues/103))
312
+ - touch events may behave unexpectedly when `syncTouch` is enabled on iOS < 16
313
+ - nested scroll containers require proper configuration to work correctly
314
+
315
+ <br>
316
+
317
+ ## Troubleshooting
318
+ - Make sure you use the latest version of [Lenis](https://www.npmjs.com/package/lenis?activeTab=versions)
319
+ - Include recommended CSS.
320
+ - Remove GSAP ScrollTrigger.
321
+ - Remove Lenis and be sure that your element/page is scrollable anyway.
322
+ - Be sure to use `autoRaf: true` or to manually call `lenis.raf(time)`.
323
+
324
+ <br>
325
+
326
+ ## Tutorials
327
+
328
+ - [Scroll Animation Ideas for Image Grids](https://tympanus.net/Development/ScrollAnimationsGrid/) by [Codrops](https://tympanus.net/codrops)
329
+ - [How to Animate SVG Shapes on Scroll](https://tympanus.net/codrops/2022/06/08/how-to-animate-svg-shapes-on-scroll) by [Codrops](https://tympanus.net/codrops)
330
+ - [The BEST smooth scrolling library for your Webflow website! (Lenis)](https://www.youtube.com/watch?v=VtCqTLRRMII) by [Diego Toda de Oliveira](https://www.diegoliv.works/)
331
+ - [Easy smooth scroll in @Webflow with Lenis + GSAP ScrollTrigger tutorial](https://www.youtube.com/watch?v=gRKuzQTXq74) by [También Studio](https://www.tambien.studio/)
332
+
333
+ <br>
334
+
335
+ ## Plugins
336
+
337
+ - [r3f-scroll-rig](https://github.com/14islands/r3f-scroll-rig) by [14islands](https://14islands.com/)
338
+ - [locomotive-scroll](https://github.com/locomotivemtl/locomotive-scroll) by [Locomotive](https://locomotive.ca/)
339
+
340
+ <br>
341
+
342
+ ## Lenis in use
343
+
344
+ - [DeSo](https://deso.com) by [Studio Freight](https://www.studiofreight.com/)
345
+ - [Sculpting Harmony](https://gehry.getty.edu/) by [Resn](https://resn.co.nz/)
346
+ - [Superpower](https://superpower.com/)
347
+ - [Daylight Computer](https://daylightcomputer.com/) by [Basement Studio](https://basement.studio/)
348
+ - [Lifeworld by Olafur Eliasson](https://lifeworld.wetransfer.com/) by Nicolas Garnier, Simon Riisnæs Dagfinrud, Lumír Španihel, Everton Guilherme, Diana Alcausin, Cristiana Sousa
349
+
350
+ <br/>
351
+
352
+ ## License
353
+
354
+ MIT © [darkroom.engineering](https://github.com/darkroomengineering)