jQuery countTo is a jQuery plugin that will count up (or down) to a target number at a specified speed, rendered within an HTML DOM element.
jQuery countTo requires the latest version of jQuery.
The most basic usage of this plugin is to create a DOM element, and apply the countTo
method to it in your JS.
<script type="text/javascript"><!--
$('.timer').countTo({from: 0, to: 500});
//--></script>
<span class="timer"></span>
A more detailed example that demonstrates all possible options being used is as follows.
<script type="text/javascript"><!--
$('.timer').countTo({
from: 50,
to: 2500,
speed: 1000,
decimals: 2,
commas: true,
refreshInterval: 50,
onComplete: function(value) {
console.debug(this);
}
});
//--></script>
<span class="timer"></span>
A complete listing of the options that can be passed to the countTo
method is below.
Option | Description |
---|---|
from | The number to start counting from. |
to | The number to stop counting at. |
speed | The number of milliseconds it should take to finish counting. |
decimals | The number of decimal points to use. |
commas | Whether to show commas in formatted number. |
refreshInterval | The number of milliseconds updating the count. |
onComplete | A callback function the is triggered when counting finishes. The final value is passed to the function, and it is run in the context of the DOM element |
jQuery-countTo is released under the MIT license.