This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.countdown.js
More file actions
64 lines (63 loc) · 1.73 KB
/
jquery.countdown.js
File metadata and controls
64 lines (63 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*!
* countdown - jQuery Plugin
* version: 1.0.4 (Mon, 21 Oct 2013)
* @requires jQuery v1.6 or later
*
* Examples at http://www.articks.ru/jquery-countdown/
*
* Copyright 2013 Dmitry Karasev
*
*/
(function($){
// Seconds in day
var days = 24*60*60;
// Seconds in hour
var hours = 60*60;
// Seconds in minute
var minutes = 60;
// Init plugin
$.fn.countdown = function(prop){
var options = $.extend({
// Callback function
callback:function(){},
// Function on timer end
finished:function(){},
// Seconds to end
seconds:0,
autocall:true
},prop);
// Left seconds
var left = 0;
// Each second
(function tick(sec){
// Current seconds to end
sec = (!sec && sec!==0) ? options.seconds : sec;
// Left seconds
left = sec;
if(left<=0) {
// If end init finished method
options.finished();
}
else {
// Math days
d = Math.floor(left/days);
left -= d*days;
// Math hours
h = Math.floor(left/hours);
left -= h*hours;
// Math minutes
m = Math.floor(left/minutes);
left -= m*minutes;
// Math seconds
s = left;
// Init callback method
options.callback(d,h,m,s,sec);
}
if(options.autocall) {
// Set timeout to repeat operations
setTimeout(function(){ tick(sec-1); },1000);
}
})();
return this;
};
})(jQuery);