I'm working on the counter using jquery. Now I'm trying to add units like K, L, M I got a script but how to implement in my code I unable to find out. My initial code:
$('.count').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function(num) {
$(this).text(Math.ceil(num));
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div><span class="count">2000</span></div>
<div><span class="count">1000</span></div>
This the link I found on the StackOverflow I want to implement in my code Found link on stack and I had tried like this
$('.count').each(function() {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function(num) {
$(this).text(Math.ceil(num));
if (num >= 1000000000) {
//$(this).text(Math.ceil(num));
return (num / 1000000000).toFixed(1).replace(/\.0$/, '') + 'G';
}
if (num >= 1000000) {
//$(this).text(Math.ceil(num));
return (num / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
}
if (num >= 100000) {
//$(this).text(Math.ceil(num));
return (num / 100000).toFixed(1).replace(/\.0$/, '') + 'L';
}
if (num >= 1000) {
//$(this).text(Math.ceil(num));
return (num / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
}
return num;
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div><span class="count">2000</span></div>
<div><span class="count">1000</span></div>
Here counter is working fine but units are not added Can anyone suggest how to append these units.