MCPcopy Create free account
hub / github.com/codrops/OnScrollShapeMorph / initSmoothScrolling

Function initSmoothScrolling

js/index.js:8–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7// Initializes Lenis for smooth scrolling with specific properties
8const 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
28const setupAnimationDefaults = (itemElement, options) => {

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected