top of page
Crumpled Fabric


Animated Number Counter

Click URL to copy

Mar 24, 2023

3 min read

WIX Ideas

Tags: JavaScript Animated Number

Wix is a well-known website builder that simplifies the process of making a beautiful website. Wix's ability to animate page components is only one of many impressive features. Here in Wix Ideas, we'll look at leveraging the user-supplied code to generate an animated number counter in Wix.

Statistics or any other numerical data can be presented in an interesting and dynamic manner with the help of an animated number counter. It's a straightforward method of making your website more engaging and attracting the attention of your target audience.

The user-provided code is written in JavaScript and runs on the Wix Corvid platform, a suite of tools that enables users to build unique features for their Wix websites. Let's go into the source code and figure out how everything fits together.

A function named countElement is called first in the code, and it accepts four parameters: element, startValue, endValue, prefix, and suffix. You can customize how a number is shown by passing in parameters for its prefix, suffix, startValue, and endValue, as well as the ID of the element to animate.

With the following lines of code, we establish two parameters: duration and increment. The increment constant determines how much the current value should be increased by at each iteration of the animation loop, while the duration constant determines the overall duration of the animation in milliseconds.

The startValue is then stored in the currentValue variable, and the setInterval method is invoked every 20 milliseconds to change both currentValue and the element's content. With Math.round, we round the current value to the nearest integer, and toLocaleString('en-US') adds commas to the string representation of the number.

Finally, the setInterval function is reset using clearInterval after an if statement determines if the animation has reached its final value.

When the #Counters element is loaded into the browser's viewport, the following code block is executed, which defines a function called countTextAnimation. Four distinct elements are animated in this function using the countElement function, each with its own unique range of values and set of prefixes and suffixes.

No prefix or suffix is attached to #text1, the first element. The second element, #text2, has the text "Member Since:" followed by a number from 0 through 2010. The third component, #text3, has the values 0–48 with the suffix “+”. The $ and /hr prefix and suffix designate the fourth element, #text4, which ranges from 0 to 50.

The countElement method is used repeatedly, with the await keyword inserted between each invocation, to guarantee that all animations are finished before moving on to the next.

In conclusion, the user-provided code is a stellar illustration of how to implement a JavaScript-based animated number counter on the Wix Corvid platform.

Using this code as-is or tweaking it to your specifications will make it simple to add interactive and attention-grabbing features to your Wix site, helping it stand out from the crowd and attract more customers.


Leave a comment (0)

Thanks for leaving a comment🎉


Conditional Dropdown Menus for Country State City

Conditional Dropdown Menus for Country State City

Add conditional dropdowns for dynamic country, state, and cities

bottom of page