CountUp.js
inorganik.github.io
inorganik.github.io
odometer(el, 42);Odometer is nifty in this way because you can still just set the value with innerHTML or .html, and it will animate it, so the overhead of adding it becomes just adding the class to whatever elements you'd like.
You can actually also manually instantiate one pretty much exactly as you described:
new Odometer({el: el, value: 42});
[1] - http://github.hubspot.com/pace/docs/welcome/One pattern I picked up from reading TJ's code is the transparent constructor...
odometer(el).value(42);
...which I like using to make things that share a bit of state, but are still one-offs, a bit terser. (Coupled with avoiding options objects in general.) Achieved with the following: function Odometer (el) {
if (!(this instanceof Odometer)) return new Odometer(el);
...
}
[1] https://github.com/component/componentI agree with wrapping the constructor function. Requiring the consumer to remember new adds one more tripping point for users. In this case, I suppose my thought was that the manual-creation path was such a small percentage of users that it wasn't a huge deal.
- merged @lifthrasiir's PR. - counts in both directions - easing optional - supports IE8 - optional callback on animation complete - coffeescript and minified versions available
It also doesn't seem to be linear, which is fine, but there should be some way to make it linear
And why just up? It'd be great if it could also count down.
You can see this if you put 6 random decimal numbers and set the duration to 20.
I tried putting 10 decimals and it just shows a string of 0s after the 2nd decimal.
I've now implemented this in my ridiculous stock-market simulator game. Looks fantastic. Many thanks OP.