lenis 1.0.44 → 1.0.45-dev.0
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/LICENSE +8 -8
- package/README.md +277 -277
- package/dist/lenis-react.mjs +1 -1
- package/dist/lenis-react.mjs.map +1 -1
- package/dist/lenis.js +306 -306
- package/dist/lenis.js.map +1 -1
- package/dist/lenis.min.js +1 -1
- package/dist/lenis.min.js.map +1 -1
- package/dist/lenis.mjs +1 -1
- package/dist/lenis.mjs.map +1 -1
- package/package.json +93 -83
package/LICENSE
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 darkroom.engineering
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 darkroom.engineering
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
[](https://github.com/darkroomengineering/lenis)
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/lenis)
|
|
5
|
-
[](https://www.npmjs.com/package/lenis)
|
|
7
|
-
[](https://bundlephobia.com/package/lenis)
|
|
8
|
-
|
|
9
|
-
## Introduction
|
|
10
|
-
|
|
11
|
-
This is our take on smooth scroll, lightweight, hard-working, smooth as butter scroll. See [Demo](https://lenis.darkroom.engineering/).
|
|
12
|
-
|
|
13
|
-
<br>
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
### JavaScript
|
|
18
|
-
|
|
19
|
-
using a package manager:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm i lenis
|
|
23
|
-
```
|
|
24
|
-
```js
|
|
25
|
-
import Lenis from 'lenis'
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
<br/>
|
|
29
|
-
|
|
30
|
-
using scripts:
|
|
31
|
-
|
|
32
|
-
```html
|
|
33
|
-
<script src="https://unpkg.com/lenis@1.0.
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<br>
|
|
38
|
-
|
|
39
|
-
## Setup
|
|
40
|
-
|
|
41
|
-
### Basic:
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
const lenis = new Lenis()
|
|
45
|
-
|
|
46
|
-
lenis.on('scroll', (e) => {
|
|
47
|
-
console.log(e)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
function raf(time) {
|
|
51
|
-
lenis.raf(time)
|
|
52
|
-
requestAnimationFrame(raf)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
requestAnimationFrame(raf)
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### GSAP ScrollTrigger:
|
|
59
|
-
```js
|
|
60
|
-
const lenis = new Lenis()
|
|
61
|
-
|
|
62
|
-
lenis.on('scroll', (e) => {
|
|
63
|
-
console.log(e)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
lenis.on('scroll', ScrollTrigger.update)
|
|
67
|
-
|
|
68
|
-
gsap.ticker.add((time)=>{
|
|
69
|
-
lenis.raf(time * 1000)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
gsap.ticker.lagSmoothing(0)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### React:
|
|
76
|
-
See documentation for [lenis/react](https://github.com/darkroomengineering/lenis/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<br/>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## Instance settings
|
|
85
|
-
|
|
86
|
-
| Option | Type | Default | Description |
|
|
87
|
-
|----------------------|-----------------------|----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
88
|
-
| `wrapper` | `HTMLElement, Window` | `window` | The element that will be used as the scroll container |
|
|
89
|
-
| `content` | `HTMLElement` | `document.documentElement` | The element that contains the content that will be scrolled, usually `wrapper`'s direct child |
|
|
90
|
-
| `eventsTarget` | `HTMLElement, Window` | `wrapper` | The element that will listen to `wheel` and `touch` events |
|
|
91
|
-
| `lerp` | `number` | `0.1` | Linear interpolation (lerp) intensity (between 0 and 1) |
|
|
92
|
-
| `duration` | `number` | `1.2` | The duration of scroll animation (in seconds). Useless if lerp defined |
|
|
93
|
-
| `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 |
|
|
94
|
-
| `orientation` | `string` | `vertical` | The orientation of the scrolling. Can be `vertical` or `horizontal` |
|
|
95
|
-
| `gestureOrientation` | `string` | `vertical` | The orientation of the gestures. Can be `vertical`, `horizontal` or `both` |
|
|
96
|
-
| `smoothWheel` | `boolean` | `true` | Whether or not to enable smooth scrolling for mouse wheel events |
|
|
97
|
-
| `syncTouch` | `boolean` | `false` | Mimic touch device scroll while allowing scroll sync (can be unstable on iOS<16)
|
|
98
|
-
| `syncTouchLerp` | `number` | `0.075` | Lerp applied during `syncTouch` inertia |
|
|
99
|
-
| `touchInertiaMultiplier` | `number` | `35` | Manage the the strength of `syncTouch` inertia |
|
|
100
|
-
| `wheelMultiplier` | `number` | `1` | The multiplier to use for mouse wheel events |
|
|
101
|
-
| `touchMultiplier` | `number` | `1` | The multiplier to use for touch events |
|
|
102
|
-
| `normalizeWheel` | `boolean` | `false` | Normalize wheel inputs across browsers (not reliable atm) |
|
|
103
|
-
| `infinite` | `boolean` | `false` | Enable infinite scrolling! ([See example](https://codepen.io/ClementRoche/pen/OJqBLod)) |
|
|
104
|
-
| `autoResize` | `boolean` | `true` | Resize instance automatically based on `ResizeObserver`. If `false` you must resize manually using `.resize()` |
|
|
105
|
-
|
|
106
|
-
<br/>
|
|
107
|
-
|
|
108
|
-
<!-- `target`: goal to reach
|
|
109
|
-
- `number`: value to scroll in pixels
|
|
110
|
-
- `string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)
|
|
111
|
-
- `HTMLElement`: DOM element
|
|
112
|
-
|
|
113
|
-
<br/>
|
|
114
|
-
|
|
115
|
-
`options`:
|
|
116
|
-
- `offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)
|
|
117
|
-
- `lerp`(`number`): animation lerp intensity
|
|
118
|
-
- `duration`(`number`): animation duration (in seconds)
|
|
119
|
-
- `easing`(`function`): animation easing
|
|
120
|
-
- `immediate`(`boolean`): ignore duration, easing and lerp
|
|
121
|
-
- `lock`(`boolean`): whether or not to prevent user from scrolling until target reached
|
|
122
|
-
- `onComplete`(`function`): called when target is reached -->
|
|
123
|
-
|
|
124
|
-
## Instance Props
|
|
125
|
-
|
|
126
|
-
| Property | Type | Description |
|
|
127
|
-
|-------------------------|---------------|-------------------------------------------------------------|
|
|
128
|
-
| `animatedScroll` | `number` | Current scroll value |
|
|
129
|
-
| `dimensions` | `object` | Dimensions instance |
|
|
130
|
-
| `direction` | `number` | `1`: scrolling up, `-1`: scrolling down |
|
|
131
|
-
| `emitter` | `object` | Emitter instance |
|
|
132
|
-
| `options` | `object` | Instance options |
|
|
133
|
-
| `targetScroll` | `number` | Target scroll value |
|
|
134
|
-
| `time` | `number` | Time elapsed since instance creation |
|
|
135
|
-
| `actualScroll` | `number` | Current scroll value registered by the browser |
|
|
136
|
-
| `velocity` | `number` | Current scroll velocity |
|
|
137
|
-
| `isHorizontal` (getter) | `boolean` | Whether or not the instance is horizontal |
|
|
138
|
-
| `isScrolling` (getter) | `boolean` | Whether or not the scroll is being animated |
|
|
139
|
-
| `isSmooth` (getter) | `boolean` | Whether or not the scroll is animated |
|
|
140
|
-
| `isStopped` (getter) | `boolean` | Whether or not the user should be able to scroll |
|
|
141
|
-
| `limit` (getter) | `number` | Maximum scroll value |
|
|
142
|
-
| `progress` (getter) | `number` | Scroll progress from `0` to `1` |
|
|
143
|
-
| `rootElement` (getter) | `HTMLElement` | Element on which Lenis is instanced |
|
|
144
|
-
| `scroll` (getter) | `number` | Current scroll value (handles infinite scroll if activated) |
|
|
145
|
-
| `className` (getter) | `string` | `rootElement` className |
|
|
146
|
-
|
|
147
|
-
<br/>
|
|
148
|
-
|
|
149
|
-
## Instance Methods
|
|
150
|
-
|
|
151
|
-
| Method | Description | Arguments |
|
|
152
|
-
|-----------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
153
|
-
| `raf(time)` | Must be called every frame for internal usage. | `time`: in ms |
|
|
154
|
-
| `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></ul> |
|
|
155
|
-
| `on(id, function)` | `id` can be any of the following [instance events](#instance-events) to listen. | |
|
|
156
|
-
| `stop()` | Pauses the scroll | |
|
|
157
|
-
| `start()` | Resumes the scroll | |
|
|
158
|
-
| `resize()` | Compute internal sizes, it has to be used if `autoResize` option is `false`. |
|
|
159
|
-
| `destroy()` | Destroys the instance and removes all events. |
|
|
160
|
-
|
|
161
|
-
## Instance Events
|
|
162
|
-
|
|
163
|
-
| Event | Callback Arguments |
|
|
164
|
-
|----------|--------------------|
|
|
165
|
-
| `scroll` | Lenis instance |
|
|
166
|
-
|
|
167
|
-
<br/>
|
|
168
|
-
|
|
169
|
-
## Recommended CSS
|
|
170
|
-
|
|
171
|
-
```css
|
|
172
|
-
html.lenis, html.lenis body {
|
|
173
|
-
height: auto;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.lenis.lenis-smooth {
|
|
177
|
-
scroll-behavior: auto !important;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.lenis.lenis-smooth [data-lenis-prevent] {
|
|
181
|
-
overscroll-behavior: contain;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.lenis.lenis-stopped {
|
|
185
|
-
overflow: hidden;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.lenis.lenis-scrolling iframe {
|
|
189
|
-
pointer-events: none;
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
<br/>
|
|
194
|
-
|
|
195
|
-
## Considerations
|
|
196
|
-
|
|
197
|
-
### Nested scroll
|
|
198
|
-
```html
|
|
199
|
-
<div data-lenis-prevent>scroll content</div>
|
|
200
|
-
|
|
201
|
-
<div data-lenis-prevent-wheel>scroll content</div>
|
|
202
|
-
|
|
203
|
-
<div data-lenis-prevent-touch>scroll content</div>
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
[See modal example](https://codepen.io/ClementRoche/pen/PoLdjpw)
|
|
207
|
-
|
|
208
|
-
### Anchor links
|
|
209
|
-
```html
|
|
210
|
-
<a href="#anchor" onclick="lenis.scrollTo('#anchor')">scroll to anchor</a>
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
<br>
|
|
214
|
-
|
|
215
|
-
## Limitations
|
|
216
|
-
|
|
217
|
-
- no support for CSS scroll-snap
|
|
218
|
-
- capped to 60fps on Safari ([source](https://bugs.webkit.org/show_bug.cgi?id=173434)) and 30fps on low power mode
|
|
219
|
-
- smooth scroll will stop working over iframe since they don't forward wheel events
|
|
220
|
-
- position fixed seems to lag on MacOS Safari pre-M1 ([source](https://github.com/darkroomengineering/lenis/issues/103))
|
|
221
|
-
|
|
222
|
-
<br>
|
|
223
|
-
|
|
224
|
-
## Tutorials
|
|
225
|
-
|
|
226
|
-
- [Scroll Animation Ideas for Image Grids](https://tympanus.net/Development/ScrollAnimationsGrid/) by [Codrops](https://tympanus.net/codrops)
|
|
227
|
-
- [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)
|
|
228
|
-
- [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/)
|
|
229
|
-
- [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/)
|
|
230
|
-
|
|
231
|
-
<br>
|
|
232
|
-
|
|
233
|
-
## Plugins
|
|
234
|
-
|
|
235
|
-
- [Loconative-scroll](https://github.com/quentinhocde/loconative-scroll#how-to-switch-from-locomotive-scroll-to-loconative-scroll) by [Quentin Hocde](https://twitter.com/QuentinHocde)
|
|
236
|
-
- [react-lenis](https://github.com/darkroomengineering/lenis/tree/main/packages/react-lenis) by [darkroom.engineering](https://darkroom.engineering/)
|
|
237
|
-
- [r3f-scroll-rig](https://github.com/14islands/r3f-scroll-rig) by [14islands](https://14islands.com/)
|
|
238
|
-
- [Lenis Scroll Snap Plugin](https://github.com/funkhaus/lenis-scroll-snap) by [Funkhaus](https://github.com/funkhaus)
|
|
239
|
-
- [locomotive-scroll](https://github.com/locomotivemtl/locomotive-scroll) by [Locomotive](https://locomotive.ca/)
|
|
240
|
-
- [vue-lenis](https://github.com/zeokku/vue-lenis) by [ZEOKKU](https://zeokku.com/)
|
|
241
|
-
- [nuxt-lenis](https://www.npmjs.com/package/nuxt-lenis) by [Milkshake Studio](https://milkshake.studio/)
|
|
242
|
-
|
|
243
|
-
<br>
|
|
244
|
-
|
|
245
|
-
## Lenis in use
|
|
246
|
-
|
|
247
|
-
- [Lunchbox](https://lunchbox.io/) by [Studio Freight](https://www.studiofreight.com/)
|
|
248
|
-
- [Easol](https://easol.com/) by [Studio Freight](https://www.studiofreight.com/)
|
|
249
|
-
- [Dragonfly](https://dragonfly.xyz/) by [Studio Freight](https://www.studiofreight.com/)
|
|
250
|
-
- [Yuga Labs](https://yuga.com/) by [Antinomy Studio](https://antinomy.studio/)
|
|
251
|
-
- [Quentin Hocde's Portfolio](https://quentinhocde.com) by [Quentin Hocde](https://twitter.com/QuentinHocde)
|
|
252
|
-
- [Houses Of](https://housesof.world) by [Félix P.](https://flayks.com/) & [Shelby Kay](https://shelbykay.dev/)
|
|
253
|
-
- [Shelby Kay's Portfolio](https://shelbykay.dev) by [Shelby Kay](https://shelbykay.dev/)
|
|
254
|
-
- [Heights Agency Portfolio](https://www.heights.agency/) by [Francesco Michelini](https://www.francescomichelini.com/)
|
|
255
|
-
- [Goodship](https://goodship.io) by [Studio Freight](https://www.studiofreight.com/)
|
|
256
|
-
- [Flayks' Portfolio](https://flayks.com) by [Félix P.](https://flayks.com/) & [Shelby Kay](https://shelbykay.dev/)
|
|
257
|
-
- [Matt Rothenberg's portfolio](https://mattrothenberg.com) by [Matt Rothenberg](https://twitter.com/mattrothenberg)
|
|
258
|
-
- [Edoardo Lunardi's portfolio](https://www.edoardolunardi.dev/) by [Edoardo Lunardi](https://www.edoardolunardi.dev/)
|
|
259
|
-
- [DeSo](https://deso.com) by [Studio Freight](https://www.studiofreight.com/)
|
|
260
|
-
- [Francesco Michelini's portfolio](https://www.francescomichelini.com/projects) by [Francesco Michelini](https://www.francescomichelini.com/)
|
|
261
|
-
|
|
262
|
-
<br/>
|
|
263
|
-
|
|
264
|
-
## Authors
|
|
265
|
-
|
|
266
|
-
This set of hooks is curated and maintained by the darkroom.engineering team:
|
|
267
|
-
|
|
268
|
-
- Clément Roche ([@clementroche\_](https://twitter.com/clementroche_)) – [darkroom.engineering](https://darkroom.engineering)
|
|
269
|
-
- Guido Fier ([@uido15](https://twitter.com/uido15)) – [darkroom.engineering](https://darkroom.engineering)
|
|
270
|
-
- Leandro Soengas ([@lsoengas](https://twitter.com/lsoengas)) - [darkroom.engineering](https://darkroom.engineering)
|
|
271
|
-
- Franco Arza ([@arzafran](https://twitter.com/arzafran)) - [darkroom.engineering](https://darkroom.engineering)
|
|
272
|
-
|
|
273
|
-
<br/>
|
|
274
|
-
|
|
275
|
-
## License
|
|
276
|
-
|
|
277
|
-
[The MIT License.](https://opensource.org/licenses/MIT)
|
|
1
|
+
[](https://github.com/darkroomengineering/lenis)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/lenis)
|
|
5
|
+
[](https://www.npmjs.com/package/lenis)
|
|
7
|
+
[](https://bundlephobia.com/package/lenis)
|
|
8
|
+
|
|
9
|
+
## Introduction
|
|
10
|
+
|
|
11
|
+
This is our take on smooth scroll, lightweight, hard-working, smooth as butter scroll. See [Demo](https://lenis.darkroom.engineering/).
|
|
12
|
+
|
|
13
|
+
<br>
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### JavaScript
|
|
18
|
+
|
|
19
|
+
using a package manager:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i lenis
|
|
23
|
+
```
|
|
24
|
+
```js
|
|
25
|
+
import Lenis from 'lenis'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
<br/>
|
|
29
|
+
|
|
30
|
+
using scripts:
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<script src="https://unpkg.com/lenis@1.0.45-dev.0/dist/lenis.min.js"></script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<br>
|
|
38
|
+
|
|
39
|
+
## Setup
|
|
40
|
+
|
|
41
|
+
### Basic:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const lenis = new Lenis()
|
|
45
|
+
|
|
46
|
+
lenis.on('scroll', (e) => {
|
|
47
|
+
console.log(e)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
function raf(time) {
|
|
51
|
+
lenis.raf(time)
|
|
52
|
+
requestAnimationFrame(raf)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
requestAnimationFrame(raf)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### GSAP ScrollTrigger:
|
|
59
|
+
```js
|
|
60
|
+
const lenis = new Lenis()
|
|
61
|
+
|
|
62
|
+
lenis.on('scroll', (e) => {
|
|
63
|
+
console.log(e)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
lenis.on('scroll', ScrollTrigger.update)
|
|
67
|
+
|
|
68
|
+
gsap.ticker.add((time)=>{
|
|
69
|
+
lenis.raf(time * 1000)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
gsap.ticker.lagSmoothing(0)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### React:
|
|
76
|
+
See documentation for [lenis/react](https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md).
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
<br/>
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Instance settings
|
|
85
|
+
|
|
86
|
+
| Option | Type | Default | Description |
|
|
87
|
+
|----------------------|-----------------------|----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
88
|
+
| `wrapper` | `HTMLElement, Window` | `window` | The element that will be used as the scroll container |
|
|
89
|
+
| `content` | `HTMLElement` | `document.documentElement` | The element that contains the content that will be scrolled, usually `wrapper`'s direct child |
|
|
90
|
+
| `eventsTarget` | `HTMLElement, Window` | `wrapper` | The element that will listen to `wheel` and `touch` events |
|
|
91
|
+
| `lerp` | `number` | `0.1` | Linear interpolation (lerp) intensity (between 0 and 1) |
|
|
92
|
+
| `duration` | `number` | `1.2` | The duration of scroll animation (in seconds). Useless if lerp defined |
|
|
93
|
+
| `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 |
|
|
94
|
+
| `orientation` | `string` | `vertical` | The orientation of the scrolling. Can be `vertical` or `horizontal` |
|
|
95
|
+
| `gestureOrientation` | `string` | `vertical` | The orientation of the gestures. Can be `vertical`, `horizontal` or `both` |
|
|
96
|
+
| `smoothWheel` | `boolean` | `true` | Whether or not to enable smooth scrolling for mouse wheel events |
|
|
97
|
+
| `syncTouch` | `boolean` | `false` | Mimic touch device scroll while allowing scroll sync (can be unstable on iOS<16)
|
|
98
|
+
| `syncTouchLerp` | `number` | `0.075` | Lerp applied during `syncTouch` inertia |
|
|
99
|
+
| `touchInertiaMultiplier` | `number` | `35` | Manage the the strength of `syncTouch` inertia |
|
|
100
|
+
| `wheelMultiplier` | `number` | `1` | The multiplier to use for mouse wheel events |
|
|
101
|
+
| `touchMultiplier` | `number` | `1` | The multiplier to use for touch events |
|
|
102
|
+
| `normalizeWheel` | `boolean` | `false` | Normalize wheel inputs across browsers (not reliable atm) |
|
|
103
|
+
| `infinite` | `boolean` | `false` | Enable infinite scrolling! ([See example](https://codepen.io/ClementRoche/pen/OJqBLod)) |
|
|
104
|
+
| `autoResize` | `boolean` | `true` | Resize instance automatically based on `ResizeObserver`. If `false` you must resize manually using `.resize()` |
|
|
105
|
+
|
|
106
|
+
<br/>
|
|
107
|
+
|
|
108
|
+
<!-- `target`: goal to reach
|
|
109
|
+
- `number`: value to scroll in pixels
|
|
110
|
+
- `string`: CSS selector or keyword (`top`, `left`, `start`, `bottom`, `right`, `end`)
|
|
111
|
+
- `HTMLElement`: DOM element
|
|
112
|
+
|
|
113
|
+
<br/>
|
|
114
|
+
|
|
115
|
+
`options`:
|
|
116
|
+
- `offset`(`number`): equivalent to [`scroll-padding-top`](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top)
|
|
117
|
+
- `lerp`(`number`): animation lerp intensity
|
|
118
|
+
- `duration`(`number`): animation duration (in seconds)
|
|
119
|
+
- `easing`(`function`): animation easing
|
|
120
|
+
- `immediate`(`boolean`): ignore duration, easing and lerp
|
|
121
|
+
- `lock`(`boolean`): whether or not to prevent user from scrolling until target reached
|
|
122
|
+
- `onComplete`(`function`): called when target is reached -->
|
|
123
|
+
|
|
124
|
+
## Instance Props
|
|
125
|
+
|
|
126
|
+
| Property | Type | Description |
|
|
127
|
+
|-------------------------|---------------|-------------------------------------------------------------|
|
|
128
|
+
| `animatedScroll` | `number` | Current scroll value |
|
|
129
|
+
| `dimensions` | `object` | Dimensions instance |
|
|
130
|
+
| `direction` | `number` | `1`: scrolling up, `-1`: scrolling down |
|
|
131
|
+
| `emitter` | `object` | Emitter instance |
|
|
132
|
+
| `options` | `object` | Instance options |
|
|
133
|
+
| `targetScroll` | `number` | Target scroll value |
|
|
134
|
+
| `time` | `number` | Time elapsed since instance creation |
|
|
135
|
+
| `actualScroll` | `number` | Current scroll value registered by the browser |
|
|
136
|
+
| `velocity` | `number` | Current scroll velocity |
|
|
137
|
+
| `isHorizontal` (getter) | `boolean` | Whether or not the instance is horizontal |
|
|
138
|
+
| `isScrolling` (getter) | `boolean` | Whether or not the scroll is being animated |
|
|
139
|
+
| `isSmooth` (getter) | `boolean` | Whether or not the scroll is animated |
|
|
140
|
+
| `isStopped` (getter) | `boolean` | Whether or not the user should be able to scroll |
|
|
141
|
+
| `limit` (getter) | `number` | Maximum scroll value |
|
|
142
|
+
| `progress` (getter) | `number` | Scroll progress from `0` to `1` |
|
|
143
|
+
| `rootElement` (getter) | `HTMLElement` | Element on which Lenis is instanced |
|
|
144
|
+
| `scroll` (getter) | `number` | Current scroll value (handles infinite scroll if activated) |
|
|
145
|
+
| `className` (getter) | `string` | `rootElement` className |
|
|
146
|
+
|
|
147
|
+
<br/>
|
|
148
|
+
|
|
149
|
+
## Instance Methods
|
|
150
|
+
|
|
151
|
+
| Method | Description | Arguments |
|
|
152
|
+
|-----------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
153
|
+
| `raf(time)` | Must be called every frame for internal usage. | `time`: in ms |
|
|
154
|
+
| `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></ul> |
|
|
155
|
+
| `on(id, function)` | `id` can be any of the following [instance events](#instance-events) to listen. | |
|
|
156
|
+
| `stop()` | Pauses the scroll | |
|
|
157
|
+
| `start()` | Resumes the scroll | |
|
|
158
|
+
| `resize()` | Compute internal sizes, it has to be used if `autoResize` option is `false`. |
|
|
159
|
+
| `destroy()` | Destroys the instance and removes all events. |
|
|
160
|
+
|
|
161
|
+
## Instance Events
|
|
162
|
+
|
|
163
|
+
| Event | Callback Arguments |
|
|
164
|
+
|----------|--------------------|
|
|
165
|
+
| `scroll` | Lenis instance |
|
|
166
|
+
|
|
167
|
+
<br/>
|
|
168
|
+
|
|
169
|
+
## Recommended CSS
|
|
170
|
+
|
|
171
|
+
```css
|
|
172
|
+
html.lenis, html.lenis body {
|
|
173
|
+
height: auto;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.lenis.lenis-smooth {
|
|
177
|
+
scroll-behavior: auto !important;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.lenis.lenis-smooth [data-lenis-prevent] {
|
|
181
|
+
overscroll-behavior: contain;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.lenis.lenis-stopped {
|
|
185
|
+
overflow: hidden;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.lenis.lenis-scrolling iframe {
|
|
189
|
+
pointer-events: none;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
<br/>
|
|
194
|
+
|
|
195
|
+
## Considerations
|
|
196
|
+
|
|
197
|
+
### Nested scroll
|
|
198
|
+
```html
|
|
199
|
+
<div data-lenis-prevent>scroll content</div>
|
|
200
|
+
|
|
201
|
+
<div data-lenis-prevent-wheel>scroll content</div>
|
|
202
|
+
|
|
203
|
+
<div data-lenis-prevent-touch>scroll content</div>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
[See modal example](https://codepen.io/ClementRoche/pen/PoLdjpw)
|
|
207
|
+
|
|
208
|
+
### Anchor links
|
|
209
|
+
```html
|
|
210
|
+
<a href="#anchor" onclick="lenis.scrollTo('#anchor')">scroll to anchor</a>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
<br>
|
|
214
|
+
|
|
215
|
+
## Limitations
|
|
216
|
+
|
|
217
|
+
- no support for CSS scroll-snap
|
|
218
|
+
- capped to 60fps on Safari ([source](https://bugs.webkit.org/show_bug.cgi?id=173434)) and 30fps on low power mode
|
|
219
|
+
- smooth scroll will stop working over iframe since they don't forward wheel events
|
|
220
|
+
- position fixed seems to lag on MacOS Safari pre-M1 ([source](https://github.com/darkroomengineering/lenis/issues/103))
|
|
221
|
+
|
|
222
|
+
<br>
|
|
223
|
+
|
|
224
|
+
## Tutorials
|
|
225
|
+
|
|
226
|
+
- [Scroll Animation Ideas for Image Grids](https://tympanus.net/Development/ScrollAnimationsGrid/) by [Codrops](https://tympanus.net/codrops)
|
|
227
|
+
- [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)
|
|
228
|
+
- [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/)
|
|
229
|
+
- [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/)
|
|
230
|
+
|
|
231
|
+
<br>
|
|
232
|
+
|
|
233
|
+
## Plugins
|
|
234
|
+
|
|
235
|
+
- [Loconative-scroll](https://github.com/quentinhocde/loconative-scroll#how-to-switch-from-locomotive-scroll-to-loconative-scroll) by [Quentin Hocde](https://twitter.com/QuentinHocde)
|
|
236
|
+
- [react-lenis](https://github.com/darkroomengineering/lenis/tree/main/packages/react-lenis) by [darkroom.engineering](https://darkroom.engineering/)
|
|
237
|
+
- [r3f-scroll-rig](https://github.com/14islands/r3f-scroll-rig) by [14islands](https://14islands.com/)
|
|
238
|
+
- [Lenis Scroll Snap Plugin](https://github.com/funkhaus/lenis-scroll-snap) by [Funkhaus](https://github.com/funkhaus)
|
|
239
|
+
- [locomotive-scroll](https://github.com/locomotivemtl/locomotive-scroll) by [Locomotive](https://locomotive.ca/)
|
|
240
|
+
- [vue-lenis](https://github.com/zeokku/vue-lenis) by [ZEOKKU](https://zeokku.com/)
|
|
241
|
+
- [nuxt-lenis](https://www.npmjs.com/package/nuxt-lenis) by [Milkshake Studio](https://milkshake.studio/)
|
|
242
|
+
|
|
243
|
+
<br>
|
|
244
|
+
|
|
245
|
+
## Lenis in use
|
|
246
|
+
|
|
247
|
+
- [Lunchbox](https://lunchbox.io/) by [Studio Freight](https://www.studiofreight.com/)
|
|
248
|
+
- [Easol](https://easol.com/) by [Studio Freight](https://www.studiofreight.com/)
|
|
249
|
+
- [Dragonfly](https://dragonfly.xyz/) by [Studio Freight](https://www.studiofreight.com/)
|
|
250
|
+
- [Yuga Labs](https://yuga.com/) by [Antinomy Studio](https://antinomy.studio/)
|
|
251
|
+
- [Quentin Hocde's Portfolio](https://quentinhocde.com) by [Quentin Hocde](https://twitter.com/QuentinHocde)
|
|
252
|
+
- [Houses Of](https://housesof.world) by [Félix P.](https://flayks.com/) & [Shelby Kay](https://shelbykay.dev/)
|
|
253
|
+
- [Shelby Kay's Portfolio](https://shelbykay.dev) by [Shelby Kay](https://shelbykay.dev/)
|
|
254
|
+
- [Heights Agency Portfolio](https://www.heights.agency/) by [Francesco Michelini](https://www.francescomichelini.com/)
|
|
255
|
+
- [Goodship](https://goodship.io) by [Studio Freight](https://www.studiofreight.com/)
|
|
256
|
+
- [Flayks' Portfolio](https://flayks.com) by [Félix P.](https://flayks.com/) & [Shelby Kay](https://shelbykay.dev/)
|
|
257
|
+
- [Matt Rothenberg's portfolio](https://mattrothenberg.com) by [Matt Rothenberg](https://twitter.com/mattrothenberg)
|
|
258
|
+
- [Edoardo Lunardi's portfolio](https://www.edoardolunardi.dev/) by [Edoardo Lunardi](https://www.edoardolunardi.dev/)
|
|
259
|
+
- [DeSo](https://deso.com) by [Studio Freight](https://www.studiofreight.com/)
|
|
260
|
+
- [Francesco Michelini's portfolio](https://www.francescomichelini.com/projects) by [Francesco Michelini](https://www.francescomichelini.com/)
|
|
261
|
+
|
|
262
|
+
<br/>
|
|
263
|
+
|
|
264
|
+
## Authors
|
|
265
|
+
|
|
266
|
+
This set of hooks is curated and maintained by the darkroom.engineering team:
|
|
267
|
+
|
|
268
|
+
- Clément Roche ([@clementroche\_](https://twitter.com/clementroche_)) – [darkroom.engineering](https://darkroom.engineering)
|
|
269
|
+
- Guido Fier ([@uido15](https://twitter.com/uido15)) – [darkroom.engineering](https://darkroom.engineering)
|
|
270
|
+
- Leandro Soengas ([@lsoengas](https://twitter.com/lsoengas)) - [darkroom.engineering](https://darkroom.engineering)
|
|
271
|
+
- Franco Arza ([@arzafran](https://twitter.com/arzafran)) - [darkroom.engineering](https://darkroom.engineering)
|
|
272
|
+
|
|
273
|
+
<br/>
|
|
274
|
+
|
|
275
|
+
## License
|
|
276
|
+
|
|
277
|
+
[The MIT License.](https://opensource.org/licenses/MIT)
|
package/dist/lenis-react.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as r}from"react/jsx-runtime";import
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";import e from"@darkroom.engineering/tempus";import n from"clsx";import t from"lenis";import{createContext as o,forwardRef as l,useRef as a,useState as c,useCallback as s,useImperativeHandle as i,useEffect as u,useContext as f}from"react";import{create as p}from"zustand";"function"==typeof SuppressedError&&SuppressedError;const m=o(null),d=p((()=>({})));function b(r,e=[],n=0){const{lenis:t,addCallback:o,removeCallback:l}=function(){const r=f(m),e=d();return null!=r?r:e}();return u((()=>{if(r&&o&&l&&t)return o(r,n),r(t),()=>{l(r)}}),[t,o,l,n,...e]),t}const y=l(((o,l)=>{var{children:f,root:p=!1,options:b={},autoRaf:y=!0,rafPriority:v=0,className:O}=o,g=function(r,e){var n={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&e.indexOf(t)<0&&(n[t]=r[t]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(t=Object.getOwnPropertySymbols(r);o<t.length;o++)e.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(r,t[o])&&(n[t[o]]=r[t[o]])}return n}(o,["children","root","options","autoRaf","rafPriority","className"]);const h=a(null),k=a(null),[N,j]=c(void 0),w=a([]),C=s(((r,e)=>{w.current.push({callback:r,priority:e}),w.current.sort(((r,e)=>r.priority-e.priority))}),[]),P=s((r=>{w.current=w.current.filter((e=>e.callback!==r))}),[]);i(l,(()=>({wrapper:h.current,content:k.current,lenis:N})),[N]),u((()=>{const r=new t(Object.assign(Object.assign({},b),!p&&{wrapper:h.current,content:k.current}));return j(r),()=>{r.destroy(),j(void 0)}}),[p,JSON.stringify(b)]),u((()=>{if(!N||!y)return;const r=e.add((r=>{null==N||N.raf(r)}),v);return()=>{r()}}),[N,y,v]),u((()=>{p&&N&&d.setState({lenis:N,addCallback:C,removeCallback:P})}),[p,N,C,P]);const S=s((r=>{for(let e=0;e<w.current.length;e++)w.current[e].callback(r)}),[]);u((()=>(null==N||N.on("scroll",S),()=>{null==N||N.off("scroll",S)})),[N,S]);const x=s((()=>{h.current&&(h.current.className=n(null==N?void 0:N.className,O))}),[N,O]);return u((()=>(x(),null==N||N.on("className change",x),()=>{null==N||N.off("className change",x)})),[N,x]),r(m.Provider,{value:{lenis:N,addCallback:C,removeCallback:P},children:p?f:r("div",Object.assign({ref:h,className:n(null==N?void 0:N.className,O)},g,{children:r("div",{ref:k,children:f})}))})}));export{y as Lenis,m as LenisContext,y as ReactLenis,y as default,b as useLenis};
|
|
2
2
|
//# sourceMappingURL=lenis-react.mjs.map
|