Lenis Configuration
Lenis is initialized with custom easing and duration settings in the main App component:src/App.tsx
Configuration Options
Scroll animation duration in seconds. Higher values create slower, more dramatic scrolling.
Custom easing function for scroll interpolation:This creates an exponential ease-out effect, starting fast and decelerating smoothly.
Enables smooth scrolling for mouse wheel events. Interpolates between discrete wheel events.
Easing Function Breakdown
The custom easing function creates a sophisticated deceleration curve:tis the progress value (0 to 1)Math.pow(2, -10 * t)creates exponential decay1.001 - ...inverts the curve for ease-out behaviorMath.min(1, ...)clamps the maximum value to 1
This easing function is similar to CSS’s
cubic-bezier(0.25, 0.46, 0.45, 0.94) but with more control over the deceleration curve.GSAP Integration
Lenis is synchronized with GSAP’s ticker for smooth animation updates:src/App.tsx
ScrollTrigger Synchronization
GSAP Ticker Integration
- Single RAF loop: Instead of multiple
requestAnimationFramecalls, GSAP manages one optimized loop - Performance: Reduces overhead by consolidating animation updates
- Synchronization: Ensures Lenis and GSAP animations run on the same timeline
The
time * 1000 conversion is necessary because GSAP’s ticker provides time in seconds, while Lenis expects milliseconds.Lag Smoothing Configuration
src/App.tsx
What is lag smoothing?
What is lag smoothing?
By default, GSAP detects when the browser is lagging (e.g., during tab switches) and adjusts animation timing to compensate. This can cause animations to “jump” forward.
Why disable it?
Why disable it?
With smooth scrolling, lag smoothing can cause jarring jumps in scroll position when returning to the tab. Setting it to
0 disables this behavior, ensuring consistent scroll physics.Trade-offs
Trade-offs
- Pro: Consistent scroll behavior across all scenarios
- Con: Animations may fall behind if the tab is backgrounded for a long time
ScrollTrigger Mobile Configuration
src/App.tsx
Cleanup and Memory Management
Proper cleanup is essential to prevent memory leaks:src/App.tsx
Complete Implementation
Here’s the full smooth scroll setup:src/App.tsx
Benefits of This Implementation
Butter-Smooth Scrolling
Interpolated scroll events create fluid motion instead of discrete jumps
Performance Optimized
Single RAF loop via GSAP ticker reduces CPU overhead
Animation Synchronization
Scroll-triggered animations stay perfectly in sync with scroll position
Customizable Easing
Fine-tuned easing function for natural deceleration
Scroll Behavior Comparison
- Native Scroll
- Lenis Smooth Scroll
- No interpolation
- Can feel jarring
- Zero overhead
Debugging Smooth Scroll
To verify Lenis is working correctly:Performance Considerations
- CPU Usage: Lenis adds ~1-2ms per frame on modern devices
- Memory: Negligible (~50KB including dependencies)
- Mobile: Works well on mobile with
smoothWheel: true - Accessibility: Respects
prefers-reduced-motion(can be configured)
Browser Compatibility
Supported: Chrome, Firefox, Safari, Edge (all modern versions)
Mobile: iOS Safari 12+, Chrome Android 80+
Fallback: Native scroll on older browsers (graceful degradation)
