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
<!-- CSS -->
<link rel="stylesheet" href="https://unpkg.com/lenis@1.1.20/dist/lenis.css">
<!-- JS -->
<script src="https://unpkg.com/lenis@1.1.20/dist/lenis.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
<!-- Anchor Links -->
<nav class="nav">
<div class="nav__inner">
<span data-anchor-target="#pink" class="nav-link">Pink</span>
<span data-anchor-target="#yellow" class="nav-link">Yellow</span>
<span data-anchor-target="#blue" class="nav-link">Blue</span>
<span data-anchor-target="#orange" class="nav-link">Orange</span>
</div>
</nav>
<!-- Sections -->
<section id="pink" class="section-resource is--pink">
<div class="section-resource__inner">
<p class="section-resource__inner-p">#pink</p>
</div>
</section>
<section id="yellow" class="section-resource is--yellow">
<div class="section-resource__inner">
<p class="section-resource__inner-p">#yellow</p>
</div>
</section>
<section id="blue" class="section-resource is--blue">
<div class="section-resource__inner">
<p class="section-resource__inner-p">#blue</p>
</div>
</section>
<section id="orange" class="section-resource is--orange">
<div class="section-resource__inner">
<p class="section-resource__inner-p">#orange</p>
</div>
</section>
HTML structure is not required for this resource.
Step 2: Add CSS
CSS
.section-resource {
justify-content: center;
align-items: center;
height: 100vh;
display: flex;
}
.section-resource__inner {
background-color: #131313;
border: 1px solid #1f1f1f;
border-radius: 2em;
justify-content: center;
align-items: center;
width: 80%;
height: 60%;
padding-left: 5%;
padding-right: 5%;
display: flex;
position: relative;
}
.section-resource.is--pink {
color: #ff98a1;
}
.section-resource.is--yellow {
color: #ffee98;
}
.section-resource.is--blue {
color: #98caff;
text-align: center;
}
.section-resource.is--orange {
color: #ff4c24;
}
.section-resource__inner-p {
text-align: center;
font-size: 5vw;
}
.nav {
z-index: 999;
grid-column-gap: 1vw;
grid-row-gap: 1vw;
pointer-events: none;
justify-content: center;
align-items: center;
width: 100%;
padding-top: 2vw;
padding-bottom: 2vw;
display: flex;
position: fixed;
bottom: 0;
left: 0;
}
.nav-link {
-webkit-user-select: none;
user-select: none;
padding-top: 1vw;
padding-bottom: 1vw;
font-size: 2vw;
transition-property: opacity;
transition-duration: .2s;
transition-timing-function: ease;
}
.nav-link:hover {
opacity: .5;
}
.nav__inner {
grid-column-gap: 2vw;
grid-row-gap: 2vw;
pointer-events: auto;
background-color: #1f1f1f;
border-radius: 30vw;
justify-content: center;
align-items: center;
padding-left: 2vw;
padding-right: 2vw;
display: flex;
}
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
// Lenis
const lenis = new Lenis({
autoRaf: true,
});
// Scroll-To Anchor Lenis
function initScrollToAnchorLenis() {
document.querySelectorAll("[data-anchor-target]").forEach(element => {
element.addEventListener("click", function () {
const targetScrollToAnchorLenis = this.getAttribute("data-anchor-target");
lenis.scrollTo(targetScrollToAnchorLenis, {
easing: (x) => (x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2),
duration: 1.2,
offset: 0 // Option to create an offset when there is a fixed navigation for example
});
});
});
}
// Initialize Scroll-To Anchor Lenis
document.addEventListener('DOMContentLoaded', () => {
initScrollToAnchorLenis();
});
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
Implementation
Anchor Links
Use [data-anchor-target="#orange"]
to scroll-to the Orange section with the id="orange"
Sections/Elements
The section/element you want to scroll-to needs a matching id (without #).
Lenis Setup
For more information on how to use Lenis: Lenis Smooth Scroll Setup
Resource Details
Last updated
January 23, 2025
Type
Osmo Basics
Category
Utilities & Scripts
Need help?
Join Slack