-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.stopwatch.js
executable file
·58 lines (47 loc) · 1.21 KB
/
jquery.stopwatch.js
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
/*
* jQuery Stopwatch plugin
*
* Copyright (c) 2011 Shawn Lee
*/
(function($) {
$.widget( "la.stopwatch", {
// set default options
options: {
interval: 1,
timer: null
},
// initialize the plugin
_create: function() {
this.options.timer = 0;
// This is bit messy, but IE is a crybaby and must be coddled.
this.element.html('<span class="min">00</span>:<span class="sec">00</span>');
},
// clean up on destroy/removal
start: function() {
var m=this.element.find('.min');
var s=this.element.find('.sec');
this.options.timer = setInterval(dotime, this.options.interval*1000);
function dotime(){
minute = parseFloat(m.text());
second = parseFloat(s.text());
second++;
if(second > 59) {
second = 0;
minute = minute + 1;
}
m.html("0".substring(minute >= 10) + minute);
s.html("0".substring(second >= 10) + second);
}
},
stop: function(){
clearInterval(this.options.timer);
this.options.timer = 0;
},
reset: function(){
clearInterval(this.options.timer);
this.options.timer = 0;
this.element.find('.min').html("00");
this.element.find('.sec').html("00");
}
});
})(jQuery);