Javascript Debt Clock

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.

Examples

Debt Clock Increasing Showing Cents

Debt clock can be used to increase in cents.

Debt Clock Increasing With Micro-cents

Change the number of fractional digits to show the value update faster

Decreasing Debt

Decreasing Debt

Extra Leading Zeroes

You can specify how many integer digits to display

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 counter

initialValue: 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 month

changeDirection: up|down
Counter direction

integerDigits: integer
The number of digits to display to the left of the decimal point in the counter

fractionDigits: integer
The number of digits to display to the right of the decimal point in the counter