Convert Figma logo to code with AI

locomotivemtl logolocomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.

8,818
1,114
8,818
24

Top Related Projects

10,481

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

The javascript library for magical scroll interactions.

28,063

Animate on scroll library

3,694

🚀 Performance focused, lightweight scroll animation library 🚀

41,869

Most modern mobile touch slider with hardware accelerated transitions

Quick Overview

Locomotive Scroll is a smooth scrolling library for modern websites. It provides a customizable and performant way to implement smooth scrolling effects, parallax animations, and scroll-based interactions in web applications.

Pros

  • Smooth and performant scrolling experience
  • Customizable with various options and callbacks
  • Supports both vertical and horizontal scrolling
  • Easy integration with modern JavaScript frameworks

Cons

  • May have a learning curve for developers new to scroll-based animations
  • Can potentially impact performance on low-end devices if not optimized properly
  • Limited browser support for older versions (IE11 and below)
  • Requires additional setup for server-side rendering environments

Code Examples

  1. Basic initialization:
import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true
});
  1. Adding parallax effect:
<div data-scroll-section>
  <img data-scroll data-scroll-speed="2" src="image.jpg" alt="Parallax Image">
</div>
  1. Triggering a callback on scroll:
scroll.on('scroll', (args) => {
  console.log('Scroll position:', args.scroll.y);
});
  1. Programmatically scrolling to an element:
scroll.scrollTo('#target-element');

Getting Started

  1. Install the package:
npm install locomotive-scroll
  1. Import and initialize in your JavaScript file:
import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true,
  multiplier: 1,
  class: 'is-inview',
});
  1. Add the necessary HTML attributes to your markup:
<div data-scroll-container>
  <section data-scroll-section>
    <h1 data-scroll>Hello, Locomotive Scroll!</h1>
  </section>
</div>
  1. Include the CSS file in your project:
<link rel="stylesheet" href="node_modules/locomotive-scroll/dist/locomotive-scroll.css">

Competitor Comparisons

10,481

Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

Pros of lax.js

  • Lightweight and simple to use, with a smaller learning curve
  • Offers a wide range of pre-built animations and effects
  • Supports both scroll-based and time-based animations

Cons of lax.js

  • Less customizable for complex scroll-based interactions
  • May require more manual setup for advanced parallax effects
  • Limited built-in support for horizontal scrolling

Code Comparison

lax.js:

lax.init()
lax.addDriver('scrollY', function() {
  return window.scrollY
})
lax.addElements('.selector', {
  scrollY: {
    translateY: [
      ["elInY", "elOutY"],
      [0, 100],
    ],
  }
})

Locomotive Scroll:

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true,
  multiplier: 1,
})
scroll.on('scroll', (instance) => {
  // Custom scroll handling
})

Both libraries offer smooth scrolling and parallax effects, but Locomotive Scroll provides more advanced features for custom scroll behaviors and complex animations. lax.js is easier to set up for simple effects, while Locomotive Scroll offers greater control and flexibility for larger projects.

The javascript library for magical scroll interactions.

Pros of ScrollMagic

  • More mature and established library with a larger community
  • Offers a wider range of animation and scrolling effects
  • Provides better documentation and examples

Cons of ScrollMagic

  • Heavier in terms of file size and performance impact
  • Less modern approach to smooth scrolling
  • Requires more setup and configuration for basic use cases

Code Comparison

ScrollMagic:

var controller = new ScrollMagic.Controller();
var scene = new ScrollMagic.Scene({
    triggerElement: "#trigger",
    duration: 300
})
.setTween("#animate", {scale: 2.5})
.addTo(controller);

Locomotive Scroll:

const scroll = new LocomotiveScroll({
    el: document.querySelector('[data-scroll-container]'),
    smooth: true
});

scroll.on('scroll', (obj) => {
    // Handle scroll event
});

ScrollMagic focuses on creating scroll-based animations and scenes, while Locomotive Scroll emphasizes smooth scrolling with simpler implementation. ScrollMagic requires more setup but offers more complex animation possibilities. Locomotive Scroll provides a more modern and performant approach to smooth scrolling with less code, making it easier to implement basic scroll-based interactions.

28,063

Animate on scroll library

Pros of AOS

  • Lightweight and easy to implement with minimal setup
  • Supports a wide range of animation effects out of the box
  • Works well with responsive designs and various screen sizes

Cons of AOS

  • Limited customization options for advanced animations
  • May not perform as smoothly on complex, long-scrolling pages
  • Lacks advanced features like parallax effects or horizontal scrolling

Code Comparison

AOS:

AOS.init({
  duration: 1000,
  easing: 'ease-in-out',
  once: true
});

Locomotive Scroll:

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true,
  multiplier: 1.0
});

AOS focuses on simple, declarative animations triggered by scrolling, while Locomotive Scroll provides a more comprehensive scrolling experience with advanced features like smooth scrolling and parallax effects. AOS is easier to implement for basic scroll animations, but Locomotive Scroll offers more control and customization for complex scrolling interactions. The choice between the two depends on the project's specific requirements and the desired level of scrolling sophistication.

3,694

🚀 Performance focused, lightweight scroll animation library 🚀

Pros of Sal

  • Lightweight and simple to use, with minimal configuration required
  • Supports a wide range of animation effects out of the box
  • Easy integration with existing projects due to its data-attribute-based approach

Cons of Sal

  • Less advanced features compared to Locomotive Scroll
  • Limited customization options for complex scroll-based animations
  • May not perform as well for large-scale, performance-critical applications

Code Comparison

Sal:

sal({
  threshold: 0.5,
  once: false,
});

Locomotive Scroll:

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true,
  multiplier: 1,
});

Key Differences

  • Sal focuses on simple scroll-based animations, while Locomotive Scroll offers more advanced scrolling features
  • Locomotive Scroll provides smoother scrolling experiences and better performance for complex layouts
  • Sal uses a simpler API and data attributes, making it easier to implement for basic use cases
  • Locomotive Scroll offers more granular control over scrolling behavior and animations

Use Cases

  • Choose Sal for quick implementation of basic scroll animations in smaller projects
  • Opt for Locomotive Scroll when building complex, high-performance websites with advanced scrolling requirements
41,869

Most modern mobile touch slider with hardware accelerated transitions

Pros of Swiper

  • More versatile, supporting various types of sliders and carousels
  • Larger community and ecosystem, with more plugins and extensions
  • Better suited for touch-enabled devices and mobile-first design

Cons of Swiper

  • Can be more complex to set up and customize for simple scrolling effects
  • May have a larger file size and performance overhead for basic use cases
  • Less focused on smooth scrolling animations compared to Locomotive Scroll

Code Comparison

Locomotive Scroll basic setup:

import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll({
  el: document.querySelector('[data-scroll-container]'),
  smooth: true
});

Swiper basic setup:

import Swiper from 'swiper';

const swiper = new Swiper('.swiper-container', {
  slidesPerView: 1,
  spaceBetween: 10,
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
});

While both libraries offer smooth scrolling capabilities, Locomotive Scroll is more focused on creating custom scroll experiences, whereas Swiper excels in creating interactive sliders and carousels. Locomotive Scroll provides a simpler API for smooth scrolling, while Swiper offers more options for slide-based content navigation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Locomotive Scroll

npm version npm downloads bundle size

A lightweight & modern scroll library for detection, animation, and smooth scrolling. Built on top of Lenis.

Documentation

Full documentation available at scroll.locomotive.ca/docs.

Quick Start

npm install locomotive-scroll
import LocomotiveScroll from 'locomotive-scroll';

const scroll = new LocomotiveScroll();
@import 'locomotive-scroll/dist/locomotive-scroll.css';
<div data-scroll data-scroll-speed="0.5">I move at half speed</div>

Features

  • Lightweight — Only 9.4kB gzipped
  • TypeScript First — Fully typed
  • Built on Lenis — Latest stable release with improved performance
  • Dual Intersection Observers — Optimized detection for triggers vs. animations
  • Smart Touch Detection — Parallax auto-disabled on mobile
  • Accessible — Native scrollbar, keyboard navigation, proper ARIA support

Demo

Check out the examples and playground

Support

GitHub Issues

NPM DownloadsLast 30 Days