• This repository has been archived on 06/Mar/2021
  • Stars
    star
    103
  • Rank 322,885 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[UNMAINTAINED] A little JavaScript cutstomizable countdown

Countdown.js

Countdown.js is a little yet customizable countdown made in pure JavaScript.

  • JSHint compliant
  • Jasmine powered-tests
  • ~2.2kb (~1kb once gzipped)
  • No dependency

Examples

// Instanciating a new countdown with all defaults
new Countdown();

// Instanciating a custom countdown
var countdown = new Countdown({
    selector: '#timer',
    msgBefore: "Will start at Christmas!",
    msgAfter: "Happy new year folks!",
    msgPattern: "{days} days, {hours} hours and {minutes} minutes before new year!",
    dateStart: new Date('2013/12/25 12:00'),
    dateEnd: new Date('Jan 1, 2014 12:00')
});

You can also play around with the code at CodePen.

Options

You can pass the constructor number of options, including:

selector

The selector you want to inject Countdown into. It should be a valid string for document.querySelector().

Default: .timer

msgBefore

The message to display before reaching dateStart.

Default: "Be ready!"

msgAfter

The message to display once reaching dateEnd.

Default: "It's over, sorry folks!"

msgPattern

The message to display during the countdown where values between braces get replaced by actual numeric values. Possible patterns:

  • {years}
  • {months}
  • {weeks}
  • {days}
  • {hours}
  • {minutes}
  • {seconds}

Default: "{days} days, {hours} hours, {minutes} minutes and {seconds} seconds left."

dateStart

The date to start the countdown to. Should be a valid instance of class Date. Documentation here at MDN.

Default: new Date() (now)

dateEnd

The date to end the countdown to. Should be a valid instance of class Date. Documentation here at MDN.

Default: new Date(new Date().getTime() + (24 * 60 * 60 * 1000)) (tomorrow)

onStart

The function to be called whenever the countdown starts.

Default: null

onEnd

The function to be called whenever the countdown stops.

Default: null

leadingZeros

Defines whether or not leading zeros are displayed when numbers are between 0 and 9.

Default: null

initialize

Defines whether or not the countdown should be initialized when instancied. If set to false, you can manually launch it with .initialize().

Default: true

jQuery events

The script doesn't require jQuery at all meanwhile it fires two events on your element if you happen to have jQuery loaded: countdownStart and countdownEnd. You can use them this way:

new Countdown({
    selector: '.timer'
})

$('.timer').on('countdownStart', function() {
    // do something
});

Grunt tasks

grunt test (running JShint and Jasmine)
grunt deploy (running UglifyJS)

More Repositories

1

sass-boilerplate

A boilerplate for Sass projects using the 7-1 architecture pattern from Sass Guidelines.
SCSS
3,318
star
2

a11y-dialog

A very lightweight and flexible accessible modal dialog script.
JavaScript
2,364
star
3

SJSJ

Simplified JavaScript Jargon
HTML
2,268
star
4

sass-guidelines

Guidelines for writing sane, maintainable and scalable Sass.
HTML
909
star
5

awesome-sass

A curated list of awesome Sass.
749
star
6

selectors-explained

A CSS selector to plain English translator.
JavaScript
205
star
7

react-a11y-dialog

A React component for a11y-dialog
TypeScript
171
star
8

SassyJSON

[UNMAINTAINED] A Sass API for JSON.
SCSS
169
star
9

jekyll-boilerplate

A cleaned up version of the initial Jekyll setup for quick use.
HTML
145
star
10

CRUD.js

A CRUD JavaScript class.
JavaScript
140
star
11

sass-compatibility

Sass compatibility issues between different engines.
SCSS
129
star
12

site

Sources for kittygiraudel.com
Liquid
101
star
13

focusable-selectors

A micro-lib exporting an array of CSS selectors for focusable HTML elements.
JavaScript
72
star
14

SassyCast

[UNMAINTAINED] Type conversion functions for Sass.
SCSS
72
star
15

SassySort

[UNMAINTAINED] Several ways to sort values in Sass using popular sorting algorithms.
SCSS
61
star
16

ImagePreloader

A lightweight JavaScript implementation of an image preloader relying on Promises.
JavaScript
61
star
17

SassyStrings

[UNMAINTAINED] A collection of Sass functions to manipulate strings.
SCSS
59
star
18

react-menu-button

A React component wrapper around inclusive-menu-button.
JavaScript
51
star
19

ama

Ask me anything!
43
star
20

SassyTester

[UNMAINTAINED] A minimalistic function tester in Sass.
SCSS
42
star
21

dotfiles

My configuration files
Shell
40
star
22

react-a11y-disclosure

A small React hook to build accessible disclosure widgets.
JavaScript
34
star
23

jekyll-styleguide

This project is an experiment about how we can create a living styleguide in Jekyll.
HTML
32
star
24

react-a11y-footnotes

A reusable React implementation of accessible footnotes.
JavaScript
32
star
25

eleventy-plugin-footnotes

An 11ty plugin to render accessible footnotes with Liquid
JavaScript
30
star
26

SassyMatrix

[UNMAINTAINED] All you ever wanted to deal with matrices in Sass.
SCSS
28
star
27

github-release-search

Tiny CLI to search for terms in GitHub releases
JavaScript
27
star
28

node-legofy

Node.js version of Legofy.
JavaScript
25
star
29

SassyGradients

[UNMAINTAINED] Sass helpers to manipulate gradients.
SCSS
24
star
30

inline-styler

A teeny tiny JavaScript library to easily manipulate the style attribute of an element.
JavaScript
22
star
31

SassyBitwise

[UNMAINTAINED] Bitwise operators in Sass.
SCSS
18
star
32

dhand

A React hook to guess the dominant hand of the user.
JavaScript
16
star
33

scrabble-helper

A CLI helper for Scrabble.
JavaScript
15
star
34

sass-semver

[UNMAINTAINED] A Sass implementation of node-semver.
SCSS
13
star
35

SassyIteratorsGenerators

[UNMAINTAINED] Iterators and generators implementation in Sass.
SCSS
13
star
36

map-dater

An interactive command line utility to estimate the age of an undated world map.
JavaScript
13
star
37

SassyLogger

[UNMAINTAINED] A logger for Sass.
SCSS
13
star
38

hangman.js

Redux powered hangman game.
JavaScript
11
star
39

circularray

A fast circular array implementation in JavaScript
JavaScript
11
star
40

advent-of-code

TypeScript
6
star
41

dependency-checker

A simple CLI script to check dependencies from a package.json
JavaScript
6
star
42

sanity-micro-client

JavaScript
5
star
43

css3-pratique

CSS 3, Pratique du Design Web
4
star
44

sudoku-solver

JavaScript
4
star
45

PHP-hangman-game

[UNMAINTAINED] A little OOPHP hangman game.
PHP
3
star
46

cypress-5570

JavaScript
2
star
47

teachable-backup

Node.js script to download all content from a Teachable school
JavaScript
1
star