top of page
Crumpled Fabric

1

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.

Code



Leave a comment (0)

Thanks for leaving a comment🎉

bromar

bromar

Sep 29, 2023

Love the tutorial!!!

You are truly great at creating these instructional videos!! Thank you! I am having trouble figuring out . . 'the triggered email' . . it is not being sent to the user submitting the form, the form and the email to the admin works great. . Could you point me to where this might have already been addressed? or any other help? On a second note. .the submit button success/failure message will go back to the default message once it's connected to the data set(I couldn't figure that out either. )

Reply

Admin

kaan

kaan

Jun 4, 2023

wishlist and rating system

hello sir I try today 2 hours but not working if you want I pay money can you do this 2 ( wishlist and rating star) system please I send to you invaid

Reply

Admin

Waqas

Waqas

Apr 16, 2023

Triggered Email Backend

Hi mate please can you send email by backend

Reply

Walter Odibi

Walter Odibi

Admin

Hi Waqas, there isn't a backend code for this tutorial. The emails will be sent from the client-side.

Ghan

Ghan

Dec 29, 2022

Great Tutorial

Hi !

First of all, I want to thank you for your great tutorials, they helped us a lot with the coding.
But I still need your help, if you don't mind. I have based on Save Calculated Field using Wix Data Hooks Codes, to code my form . but the problem is I don't know why the code only reads the computation for "week2" computation and not the "weeks"

here is the code

I also did a separate column in the dataset where the chosen datas for both fields will be placed.

$w.onReady (() => {
$w("#Person").onChange(() => {
$w("#weeks").onChange(() => {
$w("#week2").onChange(() => {
let person = Number($w("#Person").value);
let weeks = Number($w("#weeks").value);
let week2 = Number($w("#week2").value);


$w("#totalLabel").show();

$w("#totalLabel").text = `"${String(weeks * Number(person))}페소"`; //DESIGN YOUR MESSAGE
$w("#totalLabel").text = `"${String(week2 * Number(person))}페소"`; //DESIGN YOUR MESSAGE

});
});
});

});

Reply

Walter Odibi

Walter Odibi

Admin

Hi there, thanks for your comment. I see why this is a problem. The onChange() function seems wrong in combination.

To combine onChangeFunctions use this method

$w("#Person, #weeks, #weeks2").onChange(() => {

//code here

});

Walter

Walter

Aug 8, 2022

More Details? Watch video

Hi, you can click here to watch the video https://www.youtube.com/watch?v=9bx7-nBeZ5c

Reply

Walter Odibi

Walter Odibi

Admin

Walter

Walter

Jul 11, 2022

For you

Reply

Walter Odibi

Walter Odibi

Admin

Walter Odibi

Walter Odibi

Apr 18, 2022

Awesome Feature

This tutorial shows you how to display views on your Wix repeater.

📺WATCH VIDEO HERE https://www.youtube.com/watch?v=Iz7SdaCSdXg

Reply

Walter Odibi

Walter Odibi

Admin

Walter Odibi

Walter Odibi

Apr 18, 2022

Amazing tutorial

This amazing tutorial will show you how to a comment section to your WIX dynamic page.

📺WATCH VIDEO HERE https://www.youtube.com/watch?v=f8-vJQFNZ_c

Reply

Walter Odibi

Walter Odibi

Admin

Walter Odibi

Walter Odibi

Apr 10, 2022

Great Feature🎉

This amazing tutorial will show you how to add a visitor view counter to your WIX dynamic page.

🚩MORE TUTORIALS https://www.wixgenius.com/wix-tutorials

Reply

Walter Odibi

Walter Odibi

Admin

RELATED TUTORIALS 🚀

Copy Wix Page URL to Clipboard

Copy Wix Page URL to Clipboard

Allow your site visitors to easily copy any Wix page's URL to clipboard

bottom of page