How to make a loading animation in Console Application written in JavaScript or NodeJs?
Example animation or other animation.
1. --
2. \
3. |
4. /
5. --
Not really possible in browser console. In Node.js:
var twirlTimer = (function() {
var P = ["\\", "|", "/", "-"];
var x = 0;
return setInterval(function() {
process.stdout.write("\r" + P[x++]);
x &= 3;
}, 250);
})();
You can do it in the browser console as well:
var loading = (function() {
var h = ['|', '/', '-', '\\'];
var i = 0;
return setInterval(() => {
i = (i > 3) ? 0 : i;
console.clear();
console.log(h[i]);
i++;
}, 300);
})();
// clearInterval(loading) to stop it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With