HubSpot / odometer

Smoothly transitions numbers with ease. #hubspot-open-source
http://github.hubspot.com/odometer/docs/welcome
MIT License
7.3k stars 712 forks source link

How to do multiple leading zeros? #133

Open Jakobud opened 7 years ago

Jakobud commented 7 years ago

I have a number that I want to start at 0000 and use odometer to count up to 9999. But odometer displays a single zero (0) instead of 0000. Is it possible to make it pad with more zeros?

juanpasolano commented 7 years ago

have this same issue!

tomingrad commented 7 years ago

How do you put into HTML?

dynamitemedia commented 7 years ago

im having same issue as well

zorobabel commented 7 years ago

My solution (in PHP):

PHP:

$limit = 750000; // hard-coded
$num_digits = strlen( (string) $limit );
$count = 10; // hard-coded
$digits = str_split( str_pad( count, $num_digits, '0',  STR_PAD_LEFT ) );

foreach ( $digits as $digit ) {
    echo '<span class="odometer">' . $digit . '</span>';
}

JavaScript:

new Odometer({
    el: document.querySelector('.odometer')
});
wqzwh commented 6 years ago

https://github.com/wqzwh/odometer try this

Giovanni-Mattucci commented 6 years ago

@wqzwh add your unminified source code to your repository.

ganchuhang commented 6 years ago

Any respond from offical? Can add 0d' format?

wqzwh commented 6 years ago

@Giovanni #160