Back to all resources
Lenis
smooth scrolling
animation

Lenis Smooth Scrolling

By Jared Malan
This JavaScript code snippet integrates the Lenis library for smooth scrolling effects on web pages. It begins by including the Lenis library from a CDN (Content Delivery Network). After creating an instance of Lenis, it sets up an event listener that logs the scroll event details to the console whenever a scroll event occurs.

The raf function is defined to continuously update the Lenis instance with the current animation frame time, ensuring smooth animations during scroll. This function is recursively called using requestAnimationFrame, which tells the browser to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint.

The code effectively sets up a smooth scrolling effect with logging for debugging or development purposes.

Documentation: https://github.com/darkroomengineering/lenis