Reputation: 17906
I´m having this function to make a text-number count up animated. it counts up in this pattern :
[1,2,3,4,5,6,7,8,9,10,11,12,...]
function:
var pointnum = 28;
function countStuffUp(points,selector,duration) {//Animate count
$({countNum: $(selector).text()}).animate({countNum: points}, {
duration: duration,
easing:'linear',
step: function() {
$(selector).text(parseInt(this.countNum) );
},
complete: function() {
$(selector).text(points)
}
});
}
countStuffUp(pointnum,'.pointWrap',1000);
but what i want to achieve to count it up like
[01,02,03,04,05,06,07,08,09,10,11,12,...]
i tryed some sensless but i have no idea
for any hints thanks in advance
here´s a fiddle : http://jsfiddle.net/Q37Q6/
Upvotes: 1
Views: 467
Reputation: 339856
You just need a padding function:
function pad(n) {
return n < 10 ? '0' + n : n;
}
and then call that:
$(selector).text(pad(Math.floor(this.countNumber)));
NB: don't use parseInt
for truncating numbers - strictly speaking that function exists to convert strings to numbers, not for rounding.
See http://jsfiddle.net/alnitak/6BUug/1/
Upvotes: 2