jquery counter plugin
a small jquery plugin to have a countDown (or countUp).
by pixeline
HTML
<div id="demo" data-target="342">0.00000342</div>
JavaScript
(function ($) {
jQuery.fn.counter = function (options) {
var defaults = {
start: 0,
end: 10,
prefix: '',
speed: 1000
};
var o = $.extend(defaults, options);
return this.each(function () {
var $this = $(this);
$this.text(o.start);
$this.currentVal = o.start;
$this.interval = setInterval(function () {
if ($this.currentVal == o.end) {
clearInterval($this.interval);
} else if ($this.currentVal > o.end) {
$this.currentVal--;
$this.text(o.prefix + $this.currentVal);
} else {
$this.currentVal++;
$this.text(o.prefix + $this.currentVal);
}
}, o.speed);
});
}
})(jQuery);
$('#demo').counter({
start: 0,
end: ($('#demo').data('target')),
prefix: '0.00000',
speed: 10
});