jQuery: Number increment animation that works with decimals


(function ($) {
    Drupal.behaviors.stats = {
        attach: function (context, settings) {
            var elems = $('.stat-text-number').nextAll(), count = elems.length;
            $('.stat-text-number').each(function () {
                 var origonal_value = $(this).text();
                $(this).prop('Counter',0).animate({
                    Counter: $(this).text()-1,
                }, {
                        duration: 4000,
                        easing: 'swing',
                        step: function (now) {
                            $(this).text(Math.ceil(now));
                            
                        }
                    }).promise().done( function(){ $(this).text(origonal_value); } );                
            });    
        }
    };
}(jQuery));
© 2011 Adam Gerson.