Lenis Smooth Scroll Setup
Documentation
Webflow
Code
Setup: External Scripts
HTML
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lenis@1.2.3/dist/lenis.css">
<!-- JS -->
<script src="https://cdn.jsdelivr.net/npm/lenis@1.2.3/dist/lenis.min.js"></script> Step 1: Add HTML
HTML structure is not required for this resource.
Step 2: Add Javascript
Step 3: Add Javascript
Javascript
// Lenis
const lenis = new Lenis({
autoRaf: true,
});Implementation
Documentation
For all instance settings please read the Lenis Documentation on Github
Nested Scroll
For modals or other elements that have overflow: scroll; add the data-attribute [data-lenis-prevent]
Stop/Pause Scroll
Call lenis.stop(); to disable the scroll for the user, for example when opening a modal.
Start Scroll
Call lenis.start(); to enable scroll again.
Scroll-To Anchor Target
For more information how to implement lenis.scrollTo(): Lenis Scroll-To Anchor Target
Using with GSAP Scrolltrigger
// Lenis (with GSAP Scroltrigger)
const lenis = new Lenis();
lenis.on('scroll', ScrollTrigger.update);
gsap.ticker.add((time) => {lenis.raf(time * 1000);});
gsap.ticker.lagSmoothing(0);Resource details
Published
December 30, 2024
Category
Utilities & Scripts
Popularity
5.6K visitors
Need help?
Join Slack