I have this JavaScript and HTML code which work together to form a live counter when the webpage loads:
// number count for stats, using jQuery animate
$('.counting').each(function(countStats) {
var $this = $(this),
countTo = $this.attr('data-count');
$({ countNum: $this.text()}).animate({
countNum: countTo
},
{
duration: 3000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);
//alert('finished');
}
});
});
That JavaScript works in conjunction with this HTML code:
<section id="counter-stats" class="wow fadeInRight" data-wow-duration="1.4s">
<div class="container">
<div class="row">
<div class="col-lg-3 stats">
<i class="fas fa-bible" aria-hidden="true"></i>
<div class="counting" data-count="1800">0</div><span class="plusOne">+</span>
<h5>Bibles and documents available</h5>
</div>
<div class="col-lg-3 stats">
<i class="fas fa-language" aria-hidden="true"></i>
<div class="counting" data-count="700">0</div><span class="plusTwo">+</span>
<h5>Module languages</h5>
</div>
<div class="col-lg-3 stats">
<i class="fas fa-users" aria-hidden="true"></i>
<div class="counting" data-count="150000">0</div><span class="plusThree">+</span>
<h5>Users worldwide</h5>
</div>
<div class="col-lg-3 stats">
<i class="fas fa-mobile-alt" aria-hidden="true"></i>
<div class="counting" data-count="1">0</div>
<h5>Amazing Bible app</h5>
</div>
</div>
<!-- end row -->
</div>
<!-- end container -->
What I would like to do is make two minor changes. Firstly, I want to place a plus sign (+) after each counter value. Second, I would like to place a comma (,) where needed in each counter value. So it should look like the following:
1,800+
700+
150,000+
Instead of the current
1800
700
150000
I would like to make these two changes by JS, as I cannot change the CSS which restricts the placement of these characters in HTML.
Also, I would prefer it not to look with these characters awkward as the values amount dynamically.