| 6 | |
| 7 | // Initializes Lenis for smooth scrolling with specific properties |
| 8 | const initSmoothScrolling = () => { |
| 9 | // Instantiate the Lenis object with specified properties |
| 10 | lenis = new Lenis({ |
| 11 | lerp: 0.1, // Lower values create a smoother scroll effect |
| 12 | smoothWheel: true // Enables smooth scrolling for mouse wheel events |
| 13 | }); |
| 14 | |
| 15 | // Update ScrollTrigger each time the user scrolls |
| 16 | lenis.on('scroll', () => ScrollTrigger.update()); |
| 17 | |
| 18 | // Define a function to run at each animation frame |
| 19 | const scrollFn = (time) => { |
| 20 | lenis.raf(time); // Run Lenis' requestAnimationFrame method |
| 21 | requestAnimationFrame(scrollFn); // Recursively call scrollFn on each frame |
| 22 | }; |
| 23 | // Start the animation frame loop |
| 24 | requestAnimationFrame(scrollFn); |
| 25 | }; |
| 26 | |
| 27 | // Sets up default animation settings and merges with options |
| 28 | const setupAnimationDefaults = (itemElement, options) => { |