使用該插件需要引入:
<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等
最簡單的使用方式:
odometer.innerHTML = 456;
也可以如下使用:
var el = document.querySelector('.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)
附:官方API:http://github.hubspot.com/odometer/