Building Immersive Scroll Experiences with Lenis
A practical guide to buttery-smooth scrolling, scroll-linked animations, and the pitfalls to avoid when integrating Lenis into Astro projects.
Why Smooth Scroll Matters
Native browser scrolling is functional but rarely felt. Premium brand sites use scroll as a narrative device — pacing reveals, parallax depth, and section transitions that guide attention deliberately.
Lenis provides normalized scroll velocity across devices, creating the “buttery” feel users associate with high-end digital experiences.
Integration Pattern
In an Astro layout, Lenis initializes on astro:page-load to survive view transitions:
- Destroy any existing Lenis instance before reinitializing.
- Connect Lenis to
requestAnimationFramefor frame-synced updates. - Toggle
lenis-stoppedon the body when mobile menus open.
This lifecycle-aware approach prevents memory leaks and scroll conflicts during client-side navigation.
Scroll-Linked Animations
Rather than triggering animations on arbitrary timers, bind them to scroll progress:
- Parallax layers move at fractional scroll speeds.
- SVG stroke offsets map directly to scroll position.
- Opacity reveals use intersection thresholds tuned to viewport height.
The key is restraint — one or two scroll-linked effects per section create impact; more than that creates motion sickness.
Common Pitfalls
- Forgetting to destroy Lenis on page transitions (causes double-scroll handlers).
- Mixing Lenis with CSS
scroll-behavior: smooth(conflicts). - Blocking scroll without stopping Lenis when modals or drawers are open.
Final Thoughts
Lenis transforms scroll from a utility into a design medium. Combined with Astro’s minimal JS footprint, it’s one of the most effective tools for elevating agency-grade websites.