-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
69 lines (56 loc) · 1002 Bytes
/
timer.js
File metadata and controls
69 lines (56 loc) · 1002 Bytes
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
65
66
67
68
69
var count;
var timerId;
init()
function init()
{
reset();
$('#pause').on('click', pause)
$('#start').on('click', start)
$('#reset').on('click', reset)
}
function timer()
{
if (count <= 0)
clearInterval(timerId);
else
count--;
displayTime(count);
}
function displayTime(seconds)
{
var time = toMinutes(seconds);
$('#timer').html(time[0] + ':' + addZero(time[1]));
}
function toMinutes(seconds)
{
var time = [];
time[0] = Math.floor(seconds/60)
time[1] = seconds - time[0] * 60
return time;
}
function addZero(num)
{
return (String(num).length < 2) ? "0" + num : num;
}
function pause()
{
$('#pause').fadeOut(200, function () {
$('#start').fadeIn();
});
clearInterval(timerId);
}
function start()
{
$('#start').fadeOut(200, function () {
$('#pause').fadeIn();
});
timerId = setInterval(timer, 1000);
}
function reset()
{
count = 15 * 60;
$('#timer').fadeOut(200, function () {
displayTime(count);
$(this).fadeIn();
})
}