Quick and dirty javascript project to reproduce money counter timers such as like on US Debt Clock.
NOTE: Counter will begin to drift if the browser is kept open. The underlying library uses setInterval()
which is not suitable for accurately keeping time. This is more for immediate effect than for keeping the clock running continuously. The proper values are however recalculated when the page is refreshed.
Uses jQuery and jquery-counter library.
Debt clock can be used to increase in cents.
Change the number of fractional digits to show the value update faster
Decreasing Debt
You can specify how many integer digits to display
Examples
Debt Clock Increasing Showing Cents
Debt Clock Increasing With Micro-cents
Decreasing Debt
Extra Leading Zeroes
Code
Example Usage
<span class="debtclock counter counter-analog"></span>
<script>
create_money_counter('.debtclock', 10000.00, new Date(2018, 8, 23, 16, 0, 0), 5000, 'up', 7, 2);
</script>
Parameters
create_money_counter(jqSelector, initialValue, initialDate, changePerMonth,
changeDirection, integerDigits, fractionDigits);
jqSelector: string
jQuery Selector of the span that should be turned into the counterinitialValue: float
Initial value of the debt clock.initialDate: Date
The date the initial value was calculated.changePerMonth: float
The absolute value that debt clock should change per monthchangeDirection: up|down
Counter direction integerDigits: integer
The number of digits to display to the left of the decimal point in the counterfractionDigits: integer
The number of digits to display to the right of the decimal point in the counter