Dynamic counting #251
Replies: 3 comments 3 replies
-
Hey there, countUp.js is designed for doing short counting animations... maybe from like 1-10 seconds long. If you are doing something like a day counter, you would need to do that using
Or, maybe you wanted something completely different. In any case, hope that helps. |
Beta Was this translation helpful? Give feedback.
-
I'm looking for something similar, but where I get the number from an external Website that returns a JSON output. I have the following setup as of now: import { CountUp } from './countup.min.js';
window.onload = function(){
const options = {
duration: 5,
suffix: '+'
};
// example.com/json is... well... an example. It would return JSON with "number" as key.
const count = fetch('https://example.com/json', {
headers: { "Content-Type": "application/json" }
}).then(res => res.json()).then(d => d.number);
console.log(count);
const countUp = new CountUp('counter', count, options);
countUp.start();
} The browser console is returning the following info:
I never worked with Promises or JS on such a level, so if someone could give me a helping hand here would I really appreciate this. |
Beta Was this translation helpful? Give feedback.
-
I have made a variation so that it shows an incremental updated number, every 2 seconds, based on a preset final number to reach fully on a certain date. Final Date = December 1, 2021 Between dates examples: Refreshing the page will show the counter starting where it was at, before refreshing.
The loop, set at 2000 milliseconds, will stop at 100 executions and when it reaches the Final Number on December the 1st. |
Beta Was this translation helpful? Give feedback.
-
Hi,
This counter is almost exactly what I was looking for.
However, I'd need the counter to be dynamic, i.e. have the number increase every day autmatically. Unfortunately, my knowledge is limited to HTML, CSS and bit of PHP, so I'm unsure how to amend the script for this purpose.
Could anyone provide me with guidance how to amend this script to make the count increment on a daily basis by a set number (or ideally even by a random number within a given range)?
I'd truly appreciate any help!
Many thanks
Beta Was this translation helpful? Give feedback.
All reactions