home
Blogs
Category
Authors
Tell your story
<script src="https://unpkg.com/lenis@1.1.18/dist/lenis.min.js"></script>
<script>
const lenis = new Lenis()
function raf(time) {
lenis.raf(time)
requestAnimationFrame(raf)
}
requestAnimationFrame(raf)
</script><span> or <div>counter-number150).The script automatically detects the number you typed in the editor, resets it to 0, and animates it up to your target value once it enters the viewport.
</body> tag section:<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
<script>
gsap.registerPlugin(ScrollTrigger);
// Target all elements with the class .counter-number
const counters = document.querySelectorAll(".counter-number");
counters.forEach((counter) => {
const targetValue = parseInt(counter.innerText); // Get the number you typed in Webflow
counter.innerText = "0"; // Reset it to 0 before animating
gsap.to(counter, {
innerText: targetValue,
duration: 3.8,
snap: { innerText: 1 }, // Forces the number to stay an integer (no decimals)
scrollTrigger: {
trigger: counter,
start: "top 80%", // Starts when the number is 80% down the screen
}
});
});
</script>