.counter-number
) and wrap them in a scroll-triggered section.IntersectionObserver
and requestAnimationFrame
to animate numbers once when visible.To combine a JavaScript number counter animation with a scroll-triggered animation in Webflow, and trigger it only when the section is in view, follow these key steps.
0
.counter-number
, to target with JavaScript.Add an Embed element inside a page or in the Footer custom code area.
Use the following approach (simplified here for explanation):
In the script, define:
requestAnimationFrame
to count up.scroll
or IntersectionObserver
check to trigger when visible.Example outline:
Use IntersectionObserver
to detect when the number comes into view.
When triggered, animate the number from 0 to the target value (use dataset
attributes to store target numbers if needed).
Set a flag like data-done="true"
after the first animation to avoid repeats.
Here’s a simplified explanation (no raw JS blocks; write this inside an Embed component):
.counter-number
elements.IntersectionObserver
to detect when elements are visible.requestAnimationFrame
.data-animated="true"
) so the animation doesn’t repeat.Custom Code section (under Project Settings > Custom Code).
To animate numbers on scroll in Webflow: wrap number elements with an interaction trigger, detect scroll using IntersectionObserver, and run the JS count-up only once when the element is in view. This ensures smooth integration between Webflow's scroll animations and your custom animated counters.