使用该插件需要引入:
<link rel="stylesheet" href="http://github.hubspot.com/odometer/themes/odometer-theme-car.css" />
<script src="http://github.hubspot.com/odometer/odometer.js"></script>
另外官方提供了几个其他主题样式如:
odometer-theme-default.css等
最简单的使用:
<div id="my_odometer" class="odometer">0</my_odometer>
<script>
//滚动数字
setTimeout(function(){
my_odometer.innerHTML = 26004;
}, 500);
</script>
也可以自定义使用:
var el = document.querySelector('.my_odometer');
od = new Odometer({
el: el,
value: '00000000',
duration: 1000,
// Any option (other than auto and selector) can be passed in here
format: '(,ddd).dd',
theme: 'default',
animation: 'count'
});
od.update(123456)