-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (86 loc) · 2.08 KB
/
Copy pathscript.js
File metadata and controls
89 lines (86 loc) · 2.08 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*genearal stopwatch in pure javascript
* version 1
* last updated: sep 26 2013
* file name:script.js
* author:prabintp@gmail.com
*/
//class define the stopwatch
var tpStopWatch= function(){
var status = false,
time = [[0],[0,0],[0,0],[0,0]];
this.crun=function(){
var output,
hour = time[0],
minute = time[1],
second = time[2],
msecond = time[3];
if(status){
msecond[1]++;
if(msecond[1]>9){
msecond[1]=0;
msecond[0]++;
}
if(msecond[0]>9){
msecond[0]=0;
second[1]++;
}
if(second[1]>9){
second[1]=0;
second[0]++;
}
if(second[0]>5){
second[0]=0;
minute[1]++;
}
if(minute[1]>9){
minute[1]=0;
minute[0]++;
}
if(minute[0]>5){
minute[0]=0;
h[0]++;
}
if(hour[0]>23){
msecond=[0,0];
second=[0,0];
msecond=[0,0];
hour[0]=0;
}
}
//output of time to be shown
output = hour[0]+':'+minute[0]+minute[1]+':'+second[0]+second[1]+'.'+msecond[0]+msecond[1];
var time_space = document.getElementById('time');
time_space.innerHTML=output;
};
//to start the stopwatch
this.cstart=function(){
status = true;
};
//to stop the stopwatch
this.cstop = function(){
status = false;
};
//to reset stopwatch
this.creset = function(){
time = [[0],[0,0],[0,0],[0,0]];
this.cstop();
new tpStopWatch();
}
};
//create an object variable of class tpStopWatch
var y = new tpStopWatch();
var $time;
//loop for running the stopwatch, call when page onload
(function runLoop(){
y.crun();
setTimeout(runLoop,1000/100);
})();
function start() {
y.cstart();
}
function stop(){
y.cstop();
}
function reset() {
y.creset();
}