explaingit

locomotivemtl/locomotive-scroll

8,782JavaScriptAudience · designerComplexity · 2/5Setup · easy

TLDR

Locomotive Scroll is a lightweight JavaScript library that adds smooth scrolling and parallax effects to websites using simple HTML attributes, built on the Lenis smooth-scroll engine at only 9.4KB compressed.

Mindmap

mindmap
  root((Locomotive Scroll))
    What it does
      Smooth scrolling
      Parallax effects
      Scroll-triggered animation
    How it Works
      HTML data attributes
      Lenis core library
      Element visibility detection
    Features
      9.4KB compressed
      TypeScript types
      Mobile auto-disable
    Tech Stack
      JavaScript
      TypeScript
      npm
    Use Cases
      Portfolio sites
      Landing pages
      Storytelling layouts
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add smooth, fluid page scrolling to a website so users glide through content instead of jumping abruptly.

USE CASE 2

Create parallax effects where a background image drifts slowly while foreground text moves at normal scroll speed.

USE CASE 3

Trigger a CSS animation or class change on an element the moment it scrolls into the visible area of the screen.

Tech stack

JavaScriptTypeScriptnpm

Getting it running

Difficulty · easy Time to first run · 30min

Parallax effects are automatically disabled on touch devices, test on both desktop and mobile to confirm expected behavior.

In plain English

Locomotive Scroll is a JavaScript library that adds smooth scrolling and scroll-based animation effects to websites. Instead of the browser's default abrupt jump when a user scrolls, this library makes the page glide more fluidly. It also lets developers trigger animations or apply parallax effects to individual page elements as the user scrolls past them. Parallax means different parts of the page move at different speeds while scrolling, creating a sense of depth. For example, a background image might drift slowly while the text in front of it moves at normal speed. You control this by adding simple HTML attributes to elements on the page, specifying how fast each one should move relative to the scroll position. The library detects when elements come into or leave the visible area of the screen, which lets developers fire animations or class changes at the right moment. It is built on top of another library called Lenis, which handles the core smooth scrolling math. The README notes that parallax is automatically turned off on touch devices, where smooth scrolling can conflict with native mobile behavior. At 9.4 kilobytes compressed, it is designed to add minimal weight to a page. It is written in TypeScript, meaning it includes type definitions that help catch errors when using it in a development environment. Installation is through npm, the standard JavaScript package manager, and full documentation is available on the project's website.

Copy-paste prompts

Prompt 1
Show me how to install Locomotive Scroll via npm and add smooth scrolling to a long HTML page. Include the JavaScript init code and any required CSS.
Prompt 2
I want a hero background image to scroll at half the speed of the rest of the page using Locomotive Scroll. Give me the HTML data attribute for the parallax effect and the JavaScript setup.
Prompt 3
How do I trigger a CSS class called 'visible' to appear on a card element when it scrolls into view using Locomotive Scroll? Show me the HTML attribute and a JavaScript event listener example.
Prompt 4
My Locomotive Scroll site feels janky on mobile. What does the library do automatically on touch devices, and how do I verify that smooth scrolling falls back correctly?
Prompt 5
How do I update the scroll position tracker in Locomotive Scroll after adding new content to the page dynamically, for example after an infinite scroll load?
Open on GitHub → Explain another repo

← locomotivemtl on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.