I'm trying to animate with "Counter" animation some values that I get from my API by using the following method every time the data from API is changed:
$('.count').each(function() {
var $this = $(this);
jQuery({
Counter: 0
}).animate({
Counter: $this.text()
}, {
duration: 1000,
easing: 'swing',
step: function() {
$this.text(this.Counter.toFixed(2));
}
});
});
The issue is that the original value given by API in the following question is 396718.760, so formatted should be 396718.76. Still, animating it with the above function returns different values each time.
So how can I fix it by returning the correct value?
step: function (now) {
$this.text(Math.ceil(now));
}