Git Product home page Git Product logo

countdown.js's Introduction

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

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)

countdown.js's People

Contributors

kittygiraudel avatar

Watchers

James Cloos avatar Niklas Grebe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.