Copied SVG to clipboard
Something went wrong
Copied code to clipboard
Something went wrong
Saved to bookmarks!
Removed from bookmarks

Default

User image

Default

Name

  • -€50
    Upgrade to Lifetime
The Vault/

Locomotive Smooth Scroll Setup

Locomotive Smooth Scroll Setup

Documentation

Webflow

Code

Setup: External Scripts

External Scripts in Webflow

Make sure to always put the External Scripts before the Javascript step of the resource.

In this video you learn where to put these in your Webflow project? Or how to include a paid GSAP Club plugin in your project?

HTML

Copy
<!-- CSS (You read that correct, Locomotive V5 is based on Lenis) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lenis@1.2.3/dist/lenis.css">

<!-- JS -->
<script src="https://cdn.jsdelivr.net/npm/locomotive-scroll@beta/bundled/locomotive-scroll.min.js"></script> 

Step 1: Copy structure to Webflow

Copy structure to Webflow

In the video below we described how you can copy + paste the structure of this resource to your Webflow project.

Copy to Webflow

Webflow structure is not required for this resource.

Step 1: Add HTML

HTML

Copy

HTML structure is not required for this resource.

Step 2: Add CSS

CSS

Copy

Step 2: Add custom Javascript

Custom Javascript in Webflow

In this video, Ilja gives you some guidance about using JavaScript in Webflow:

Step 2: Add Javascript

Step 3: Add Javascript

Javascript

Copy
// Initialize Locomotive Scroll
const locomotiveScroll = new LocomotiveScroll();

Step 3: Add custom CSS

Step 2: Add custom CSS

Custom CSS in Webflow

Curious about where to put custom CSS in Webflow? Ilja explains it in the below video:

CSS

Copy

Documentation

For all instance settings please read the Locomotive Scroll v5 Documentation.

Attributes

We highlighted some of the available attributes. Please read the documentation for all options.

  • data-scroll Enable viewport detection on an element.
  • data-scroll-speed Example: 0.1 or -0.05
  • data-scroll-offset Example: 25%, 50%
<h2 data-scroll data-scroll-speed="-0.5" data-scroll-offset="50%, 50%">What's up?</h2>
<p data-scroll data-scroll-speed="0.1">😬</p>

Options

Locomotive Scroll can use a lot of the options defined by Lenis, for a full list check out the documentation.

// Initialize Locomotive Scroll
const locomotiveScroll = new LocomotiveScroll({
  lenisOptions: {
    // Options (https://scroll.locomotive.ca/docs#/options)
    lerp: 0.1,
    duration: 1.2,
    easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
  }
});

Start Scroll

Call locomotiveScroll.start(); to enable scroll again.

// Don't start Locomotive on load
const locomotiveScroll = new LocomotiveScroll({
  autoStart: false,
});

// Manually start it
function startScroll() {
  locomotiveScroll.start();
}

Stop/Pause Scroll

Call locomotiveScroll.stop(); to disable the scroll for the user, for example when opening a modal.

Destroy Scroll

Call locomotiveScroll.destroy(); to destroy the scroll.

Nested Scroll

For modals or other elements that have overflow: scroll; add the data-attribute [data-lenis-prevent]

Lenis Resources

To have a more basic setup with just Lenis check out our Lenis Smooth Scroll Resource.

Resource Details

Smooth
Scrolling
Locomotive
Progress
Parallax

Original source

Osmo

Creator Credits

We always strive to credit creators as accurately as possible. While similar concepts might appear online, we aim to provide proper and respectful attribution.