Configs2026年5月20日·1 分钟阅读

Lenis — Smooth Scroll Library for Modern Websites

A lightweight smooth scrolling library that provides buttery-smooth native scroll feel with inertia, perfect for creative websites, parallax effects, and scroll-driven animations.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Lenis Overview
通用 CLI 安装命令
npx tokrepo install 64ac14fe-548a-11f1-9bc6-00163e2b0d79

Introduction

Lenis is a smooth scroll library that intercepts native browser scrolling and applies inertia-based easing for a fluid, polished feel. It is designed for creative and portfolio websites where scroll-driven animations, parallax effects, and smooth page transitions are essential to the user experience.

What Lenis Does

  • Overrides native scroll behavior with configurable inertia and easing curves
  • Works on both vertical and horizontal scroll containers
  • Integrates with GSAP ScrollTrigger and other scroll-driven animation libraries
  • Provides scroll-to functionality with smooth animated transitions
  • Supports touch devices, trackpads, and mouse wheels with consistent behavior

Architecture Overview

Lenis listens to wheel, touch, and keyboard scroll events and translates them into a virtual scroll position. On each animation frame, it interpolates between the current and target scroll positions using a configurable lerp factor, then applies the result via window.scrollTo or a container's scrollTop. This approach preserves native scroll features like accessibility and find-in-page while adding smooth interpolation.

Self-Hosting & Configuration

  • Install from npm and import into any JavaScript or TypeScript project
  • Create a Lenis instance and drive it with requestAnimationFrame or GSAP ticker
  • Set duration, easing, and lerp to control smoothness and responsiveness
  • Use orientation: 'horizontal' for horizontal scroll layouts
  • Call lenis.scrollTo(target) for programmatic smooth scroll to anchors or positions

Key Features

  • Sub-2 KB gzipped with no dependencies
  • Preserves native accessibility features like keyboard navigation and anchors
  • GSAP ScrollTrigger integration with a single line of setup
  • Touch and trackpad inertia that feels natural on all devices
  • Scroll lock and unlock API for modals and overlays

Comparison with Similar Tools

  • Locomotive Scroll — Feature-rich with parallax built in; Lenis is lighter and more focused on scroll feel
  • GSAP ScrollSmoother — Part of the GSAP paid tier; Lenis is fully open source
  • Smooth Scrollbar — Custom scrollbar approach; Lenis uses native scroll position for better compatibility
  • CSS scroll-behavior: smooth — Browser-native but limited to anchor links with no inertia control

FAQ

Q: Does Lenis affect page accessibility? A: Lenis preserves native scroll position and keyboard navigation. Screen readers and find-in-page continue to work normally.

Q: Can I use Lenis with React or Next.js? A: Yes. Initialize it in a useEffect hook or use the community React wrapper. It works with any framework.

Q: How do I integrate with GSAP ScrollTrigger? A: Connect Lenis to GSAP's ticker with gsap.ticker.add((time) => lenis.raf(time * 1000)) and set ScrollTrigger.defaults({ scroller: document.body }).

Q: Does it work on mobile? A: Yes. Lenis handles touch events and can be configured with different easing for touch devices.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产