/wheeltimecounter

jQuery number ticker/counter

Primary LanguageJavaScript

WheelTimeCounter is a jQuery plugin to simulate a real-time numeric counter without needing to poll in real-time.

The wheelTimeCounter object has an updateAndWait callback (suitable for inserting into a jQuery.ajax onSuccess callback) that takes two parameters: the target value to count towards, and how long it can and should take to get there. At any time after that, you can updateAndWait with a new target value and new amount of delay, and the counter will adjust its counting rate as necessary.

The displayed value will only ever "catch up" to the target value if the amount of time specified has elapsed before a new target is set.

There are also a few options:
- you can set the animation speed (time between display updates)
- you can pass in a formatter method to format the numbers as desired (e.g. from 100 to "$1.00")
- you can set a "quantum" which changes the amount the display value will increment by (the default is to increment by the smallest integer possible given the effective speed)

An example that shows all of the options is in test/index.html.

TODO:
This plugin doesn't currently respect the way plugins generally work -- it returns a new object with methods rather than the original jQuery object it was called on.