Skip to content

jysir99/fliptimer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

FlipTimer

⏰ A lightweight and performant flip style timer, built with https://github.com/PButcher/fliptimer.

Features

  • 💡 Lightweight - No jQuery! <11KB minified bundle
  • ⚡ Performant - Animations powered by CSS transitions
  • 📱 Responsive - Works great on screens of all sizes
  • 🎨 Themeable - Choose from built-in themes, or add your own
  • 🌍 i18n - Customisable headings for your language

Basic Usage

new FlipTimer(1538137672).start();

Include the CSS and JS in <head> and include the following line in your HTML.

<div id="fliptimer" class="fliptimer"></div>

See a full example here.

Multiple Instances

To use multiple instances of FlipTimer on the same page, specify a DOM element ID as the second argument in FlipTimer's constructor:

new FlipTimer(1588017373, "registerBy").start();
new FlipTimer(1593561600, "eventStart").start();
<div id="registerBy" class="FlipTimer"></div>
<div id="eventStart" class="FlipTimer"></div>

Themes

FlipTimer comes with 2 themes as standard:

  • dark [default]
  • light

To change the theme, you can supply the theme property in the opt object in the constructor with the theme name as a string:

{
  theme: "light";
}

For example, to instantiate FlipTimer using the light theme instead:

new FlipTimer(1538137672, {
  theme: "light",
}).start();

Custom Themes

Custom themes can be added by adding a new stylesheet using the FlipTimer theme template.

FlipTimer themes must have the class name prefix of: .FlipTimer__theme- followed by the name of your theme. For example, the standard theme class names are:

  • .FlipTimer__theme-dark
  • .FlipTimer__theme-light

You can then load your theme by specifying the theme property in the opt object of the constructor (see Themes).

Headings

You can add your own rotor group headings by passing an array as part of the opt object. 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 FlipTimer(1538137672, {
  headings: ["Nap", "Óra", "Perc", "Másodperc"],
}).start();

Note that headings will default to English if not provided: ["Days", "Hours", "Minutes", "Seconds"]

API

FlipTimer.prototype.constructor(uts, [el], [opts])

Create a new FlipTimer instance.

Parameters

uts

Type: number

The unix timestamp to count down to (in seconds).

[el]

Optional
Type: string (default: FlipTimer)

The DOM element ID to attach this FlipTimer instance to. Defaults to FlipTimer.

[opts]

Optional
Type: object (default: {})

Optionally specify additional configuration settings. Currently supported settings include:

FlipTimer.prototype.start()

Start the timer.

FlipTimer.prototype.ifEnded(callback)

Call a function once the timer has ended.

Parameters

callback

Type: function

Function to execute once the timer has ended.

Example

var FlipTimer = new FlipTimer(1538137672)

  // Start the timer
  .start()

Acknowledgements

Thanks to the following people for their suggestions/fixes:

  • @chuckbergeron for his help with making FlipTimer responsive.
  • @vasiliki-b for spotting and fixing the Safari backface-visibility issue.
  • @joeinnes for adding i18n to rotor group headings.

About

⏰ A lightweight and performant flip style timer, 一个翻页正计时库(因为作者没有实现正计时)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 57.3%
  • CSS 39.0%
  • HTML 3.7%