fancy-timer
Digital countdown timer, clock and more
Demo with code examples
https://lexxus.github.io/fancy-timer/
Install
npm i fancy-timer
Usage
Firstly apply CSS file in the <head>
tag.
Then apply this CSS classes to a container element.
If you want to use dark theme replace class ft-light
to ft-dark
.
Simple time count
This example just counts seconds from start.
; ;;
Countdown timer with warning
This example setup the countdown timer for 5 minutes (300 seconds). When one minute left it enables warning mode. On finish it calls a callback function.
; ; value: 300, direction: -1, warn: , onWarning , onFinish };;
New Year countdown
This example set the countdown timer to New Year with the captions.
; ; value: new Date`-01-01`, captions: , showDays: 3}; // initialize the timer; // Start the timerft.start-1;
Options
Methods
FancyTimer.startdirection?: 1 | 0 | -1
Start the timer in specified direction: 1 - forward, -1 - backward.
If direction
is 0 or omitted, using current direction
property value.
FancyTimer.stop
Stop the timer.
FancyTimer.updatevalue: number, force = false
Update displaying time.
value
is in seconds.
If force = true
it means the timer updates immetiately without animation.
This method is not updating any option, so after call start
method the timer will display an actual value
property.
FancyTimer.updateOptionsoptions: IFancyTimerOptions
This method allows to update all options except captions
and showDays
.
If some options are not specified they will be set as undefined
(except value
, captions
, showDays
).
FancyTimer.setValuevalue?: number | Date | string
This method is very handy if need to update only value
property.