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
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js"></script>
<!-- Optional if you want to have the 'click to scroll to' functionality-->
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollToPlugin.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
<div class="progress-bar-wrap">
<div class="progress-bar"></div>
</div>
HTML structure is not required for this resource.
Step 2: Add CSS
CSS
.progress-bar-wrap {
z-index: 10;
cursor: pointer;
width: 100%;
height: 1.5rem;
transition: background-color .2s;
position: fixed;
inset: 0% 0% auto;
}
.progress-bar-wrap:hover {
background-color: #0000000d;
}
.progress-bar {
transform-origin: 0%;
transform-style: preserve-3d;
background-color: #ff4c24;
width: 100%;
height: 100%;
transform: scale3d(0, 1, 1);
}
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
gsap.registerPlugin(ScrollTrigger,ScrollToPlugin);
document.addEventListener("DOMContentLoaded", ()=> {
const progressBar = document.querySelector('.progress-bar');
const progressBarWrap = document.querySelector('.progress-bar-wrap');
// Animate the progress bar as you scroll
gsap.to(progressBar, {
scaleX: 1,
ease: 'none', // no ease, we control smoothness with the 'scrub' property
scrollTrigger: {
trigger: document.body, // Track the entire page
start: 'top top',
end: 'bottom bottom',
scrub: 0.5, // control the amount of time it takes for the bar to catch up with scroll position
},
});
// Click listener to scroll to a specific position, feel free to remove if you dont want it!
progressBarWrap.addEventListener('click', (event) => {
const clickX = event.clientX;
const progress = clickX / progressBarWrap.offsetWidth;
const scrollPosition = progress * (document.body.scrollHeight - window.innerHeight);
gsap.to(window, {
scrollTo: scrollPosition,
duration: 0.725,
ease: 'power3.out',
});
});
})
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
Click-to-scroll option
For demo purposes, we've added a click listener on the progress-bar-wrap
. This is of course optional, so if you don't want this feature, feel free to remove the entire click event listener and remove the GSAP ScrollToPlugin.
Resource Details
Last updated
January 22, 2025
Type
The Vault
Category
Scroll Animations
Need help?
Join Slack