Skip to content

Design5 min read

Add a scroll-triggered number animation from X to X

Introduction

VariableExample valueDescription
DUREE60000Total duration in milliseconds
VALEUR_FINALE12000000Target value to reach
INTERVALLE10Update frequency (in ms)
valeurActuelle1000000Starting value

In this tutorial, Sandro, cofounder of Gemeos Webflow agency, shows you how to add a number scroll animation from X to X.

Adding a number scroll from one value to another on a website can serve several purposes:

  1. Grab attention : Motion naturally catches the human eye. A scroll animation can therefore be used to highlight a specific piece of information or an announcement the site’s designers want visitors to notice.
  2. Dynamic feel : The scroll animation can give a website a modern, dynamic look, although that effect depends a lot on current design trends.
  3. Navigation : In some cases, scrolling can be used as a navigation element, guiding users to different sections of a website or to external links.

That said, there are also downsides to using a text scroll:

  • Readability : Moving text can be hard for some users to read.
  • Accessibility : Scroll animations can create issues for users with disabilities, especially those who use screen readers.
  • Compatibility : Not all browsers and devices handle animations well, which can lead to display issues.
  • Distraction : If used poorly, a scroll animation can distract more than it informs, especially if other elements on the site are moving too.

If you’re thinking about adding text scroll to your website, it’s essential to weigh the pros and cons, and always test the feature on different devices and browsers to ensure a great user experience.

Here’s how to add it to your Webflow site

Add this script in the <head> of your page

Be sure to replace the {votre-id} variable with the ID used in the previous step

<script>
const DUREE = 60000; // Total duration of the animation in milliseconds (1 minute)
const VALEUR_FINALE = 12000000; // The target value

const INTERVALLE = 10; // in milliseconds
const AUGMENTATION = VALEUR_FINALE / (DUREE / INTERVALLE);

let valeurActuelle = 1000000;
const element = document.getElementById("{your-id}");

const interval = setInterval(() => {
    valeurActuelle += AUGMENTATION;

    // To make the hundreds animation feel dynamic
    const animationCentaines = Math.floor(Math.random() * 100);

    let valeurAffichee = valeurActuelle + animationCentaines;

    // If we go past the final value, stop the interval
    if (valeurActuelle >= VALEUR_FINALE) {
        clearInterval(interval);
        valeurAffichee = VALEUR_FINALE;
    }

    // Format with a comma as the thousands separator and add the $ symbol
    element.textContent = '$' + Math.round(valeurAffichee).toLocaleString('en-US');
    
}, INTERVALLE);
</script>

Customize the code for a result that fits your needs

Change the duration

Represents the total duration of the animation in milliseconds (60 seconds, or 1 minute in this example).

Change the final value

Your target or final value that the animation should reach in milliseconds.

Change the interval

Represents how often the current value will be updated, in milliseconds.

Change the starting value

Initializes the current value at 1,000,000 (starting value).

Bonus

Generates a random number between 0 and 99. Used to give the hundreds a dynamic animation effect as they display.

US formatting with a comma as the thousands separator and the $ symbol added. To get a € result and French formatting, you can use the following code

Just remove this part of the code to remove the formatting and the unit!

Publish and you’re done

Published on Apr 10, 2025

Sandro DA SILVA

Growth Marketer, Webflow expert, and jack-of-all-trades. Sandro handles commercial operations, ensures projects run smoothly, and addresses marketing-related issues (SEO, Tracking, Copywriting, etc).

You're going to working with us, guaranteed

Ready to launch your business?

get a quote

Let’s f*****G GO !!