implement_lenis_scroll

Implement Lenis Smooth Scroll

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "implement_lenis_scroll" with this command: npx skills add jerrar670/surf-website/jerrar670-surf-website-implement-lenis-scroll

Implement Lenis Smooth Scroll

This skill guides you through adding buttery smooth scrolling to a React/Next.js application using @studio-freight/lenis (or the newer lenis package).

Prerequisites

  • A React or Next.js project.

Steps

  1. Install Dependencies

Install the Lenis package.

npm install lenis

OR depending on version preference

npm install @studio-freight/lenis

  1. Create the Lenis Hook/Component

It's best to encapsulate Lenis in a reusable component or hook.

Option A: Global Component (Recommended for Next.js App Router) Create src/lib/lenis.ts or src/components/SmoothScroll.tsx .

// src/components/SmoothScroll.tsx 'use client'

import { ReactNode, useEffect } from 'react' import Lenis from 'lenis'

export default function SmoothScroll({ children }: { children: ReactNode }) { useEffect(() => { const lenis = new Lenis({ duration: 1.2, easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), orientation: 'vertical', gestureOrientation: 'vertical', smoothWheel: true, })

function raf(time: number) {
  lenis.raf(time)
  requestAnimationFrame(raf)
}

requestAnimationFrame(raf)

return () => {
  lenis.destroy()
}

}, [])

return <>{children}</> }

  1. Integrate into Layout

Wrap your main application or layout content with the component.

Next.js App Router (layout.tsx ):

import SmoothScroll from '@/components/SmoothScroll'

export default function RootLayout({ children }) { return ( <html lang="en"> <body> <SmoothScroll> {children} </SmoothScroll> </body> </html> ) }

Best Practices

  • Performance: Ensure requestAnimationFrame is optimized.

  • Scroll Restoration: Lenis usually handles this, but verify scrollRestoration works as expected in Next.js.

  • GSAP Integration: If using ScrollTrigger, ensure you update ScrollTrigger on Lenis scroll. // Inside useEffect // lenis.on('scroll', ScrollTrigger.update) // gsap.ticker.add((time)=>{lenis.raf(time * 1000)}) // gsap.ticker.lagSmoothing(0)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

premium_web_design

No summary provided by upstream source.

Repository SourceNeeds Review
General

image-gen

Generate AI images from text prompts. Triggers on: "生成图片", "画一张", "AI图", "generate image", "配图", "create picture", "draw", "visualize", "generate an image".

Archived SourceRecently Updated
General

explainer

Create explainer videos with narration and AI-generated visuals. Triggers on: "解说视频", "explainer video", "explain this as a video", "tutorial video", "introduce X (video)", "解释一下XX(视频形式)".

Archived SourceRecently Updated
General

asr

Transcribe audio files to text using local speech recognition. Triggers on: "转录", "transcribe", "语音转文字", "ASR", "识别音频", "把这段音频转成文字".

Archived SourceRecently Updated