Download
Demo
- Overview
- Documents
User Rating: 0/5 ( 0 votes)
Your Rating:
Countdown is a jquery countdown plugin that customize content, layout, style by add html attribute to the children of countdown container
Source: fengyuanchen.github.io
1. INCLUDE JS FILES
<script src="/path/to/jquery.js"></script><!-- jQuery is required --> <script src="/path/to/countdown.js"></script>
2. HTML
<p class="countdown">Dec 31 2014 23:59:59</p>
3. JAVASCRIPT
$(".countdown").countdown();
4. OPTIONS
Setup with $("#target").countdown(options), or global setup with $.fn.countdown.setDefaults(options).
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-fast="true".
| Name | Type | Default | Description |
|---|---|---|---|
| autoStart | boolean | true | Auto start the countdown when initialized. |
| date | object / number / string | null | The target date, allow date object, time number (milliseconds), valid date string. |
| fast | boolean | false | Set it `true` to update the date number per one tenth second. |
| end | function | function() {} | The function will be run when the countdown end. |
| text | string | "%s days, %s hours, %s minutes, %s seconds" | Just a text template, you can customize it, e.g., "%s D / %s H / %s M / %s S". |
5. METHODS
- start - Start the countdown
- stop - Stop the countdown
- end - End the countdown
- destroy - Destroy the countdown
Usage
HTML:
<p id="countdown-methods">Jan 1 2015 00:00:00</p> <button id="countdown-start">Start</button> <button id="countdown-stop">Stop</button> <button id="countdown-end" class="btn btn-success">End</button> <button id="countdown-destroy" class="btn btn-danger">Destroy</button>
JavaScript:
var $countdownMethods = $("#countdown-methods");
$countdownMethods.countdown({
autoStart: false
});
$("#countdown-start").click(function() {
$countdownMethods.countdown("start");
});
$("#countdown-stop").click(function() {
$countdownMethods.countdown("stop");
});
$("#countdown-end").click(function() {
$countdownMethods.countdown("end");
});
$("#countdown-destroy").click(function() {
$countdownMethods.countdown("destroy");
});
6. EXAMPLES
Customize text
<p countdown data-text="Christmas Day Countdown: %s Days / %s Hours / %s Minutes / %s Seconds">Dec 25 2014 00:00:00</p>
I18n - zh-CN
<p countdown data-date="Dec 25 2014" data-text="圣诞节倒计时:%s 天 %s 时 %s 分 %s 秒"></p>
Change view with end function
HTML:
<p id="countdown-option-end"></p>
JavaScript:
var $countdownOptionEnd = $("#countdown-option-end");
$countdownOptionEnd.countdown({
date: (new Date()).getTime() + 60 * 1000, // 1 minute later
fast: true,
end: function() {
$countdownOptionEnd.text("Countdown end!");
}
});
JS Tutorial
