⏰ A lightweight and performant flip styled countdown clock
⏰ A lightweight and performant flip styled countdown clock.
Example live at: https://pbutcher.uk/flipdown/
Remix FlipDown on CodePen: https://codepen.io/PButcher/pen/dzvMzZ
To get started, either clone this repo or install with
npm install flipdownor
yarn add flipdown.
For basic usage, FlipDown takes a unix timestamp (in seconds) as an argument.
new FlipDown(1538137672).start();
Include the CSS and JS in
and include the following line in your HTML.See a full example here.
To use multiple instances of FlipDown on the same page, specify a DOM element ID as the second argument in FlipDown's constructor:
new FlipDown(1588017373, "registerBy").start(); new FlipDown(1593561600, "eventStart").start();
FlipDown comes with 2 themes as standard:
To change the theme, you can supply the
themeproperty in the
optobject in the constructor with the theme name as a string:
{ theme: "light"; }
For example, to instantiate FlipDown using the light theme instead:
new FlipDown(1538137672, { theme: "light", }).start();
Custom themes can be added by adding a new stylesheet using the FlipDown theme template.
FlipDown themes must have the class name prefix of:
.flipdown__theme-followed by the name of your theme. For example, the standard theme class names are:
.flipdown__theme-dark
.flipdown__theme-light
You can then load your theme by specifying the
themeproperty in the
optobject of the constructor (see Themes).
You can add your own rotor group headings by passing an array as part of the
optobject. Bear in mind this won't change the functionality of the rotors (eg: the 'days' rotor won't magically start counting months because you passed it 'Months' as a heading).
Suggested use is for i18n. Usage as follows:
new FlipDown(1538137672, { headings: ["Nap", "Óra", "Perc", "Másodperc"], }).start();
Note that headings will default to English if not provided:
["Days", "Hours", "Minutes", "Seconds"]
FlipDown.prototype.constructor(uts, [el], [opts])
Create a new FlipDown instance.
uts
Type: number
The unix timestamp to count down to (in seconds).
[el]
Optional
Type: string (default:
flipdown)
The DOM element ID to attach this FlipDown instance to. Defaults to
flipdown.
[opts]
Optional
Type: object (default:
{})
Optionally specify additional configuration settings. Currently supported settings include:
FlipDown.prototype.start()
Start the countdown.
FlipDown.prototype.ifEnded(callback)
Call a function once the countdown has ended.
callback
Type: function
Function to execute once the countdown has ended.
var flipdown = new FlipDown(1538137672)// Start the countdown .start()
// Do something when the countdown ends .ifEnded(() => { console.log("The countdown has ended!"); });
Thanks to the following people for their suggestions/fixes: