Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery animation number from to

There is a problem with that animation I found here : jQuery animated number counter from zero to value

Here is the problem, I used it on test website and the counter don't go on the exact value when it's with big numbers.

here's the HTML :

<span class="Count">66620</span>
 <br/>
<span class="Count">66666666</span>
 <br/>
<span class="Count">66666666</span>

here's the javascript :

$('.Count').each(function () {
  var $this = $(this);
  jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
    duration: 1000,
    easing: 'swing',
    step: function () {
      $this.text(Math.ceil(this.Counter));
    }
  });
});

http://jsfiddle.net/Yy6r6/68/

Do someone have an idea ?

Thanks in advance.

like image 814
Slater Avatar asked Sep 30 '22 06:09

Slater


1 Answers

Why not simply use the first argument of the callback?

step

Type: Function( Number now, Tween tween )

step: function (i) {
    $this.text(Math.ceil(i));
}

http://jsfiddle.net/Yy6r6/70/

like image 87
Johan Avatar answered Oct 15 '22 19:10

Johan