-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (70 loc) · 2.4 KB
/
index.html
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
<!DOCTYPE html>
<html lang='ja'>
<head>
<meta charset='utf-8'>
<title>StopWatch</title>
<style type='text/css'>
#display {
height: 20px;
}
</style>
</head>
<body>
<h1>StopWatch</h1>
<div id='display'></div>
<div id='actions'>
<button id='start'>START</button>
<button id='stop'>STOP</button>
<button id='lap'>LAP</button>
<button id='reset'>RESET</button>
</div>
<script type='text/javascript' src='./stopwatch.js'></script>
<script type='text/javascript'>
var StopWatchComponent = function(){
this.display = document.getElementById('display');
this.actions = document.getElementById('actions');
this.startBtn = document.getElementById('start');
this.stopBtn = document.getElementById('stop');
this.lapBtn = document.getElementById('lap');
this.resetBtn = document.getElementById('reset');
this.addEvent();
};
StopWatchComponent.prototype.renderTime = function(){
this.display.innerHTML = this.stopWatch.processTime/1000;
};
StopWatchComponent.prototype.rerender = function(){
this.timerID = setInterval(this.renderTime.bind(this),1);
};
StopWatchComponent.prototype.start = function(){
if (!this.stopWatch.start()) return false;
this.rerender();
};
StopWatchComponent.prototype.stop = function(){
if (!this.stopWatch.stop()) return false;
clearInterval(this.timerID);
};
StopWatchComponent.prototype.lap = function(){
if (!this.stopWatch.lap()) return false;
console.log(this.stopWatch.lapTimes);
console.log(this.stopWatch.getTotalTime());
};
StopWatchComponent.prototype.reset = function(){
if (this.timerID !== 0) {
this.stopWatch.stop();
};
this.stopWatch.reset();
this.display.innerHTML = 0;
};
StopWatchComponent.prototype.addEvent = function(){
function hello(){
console.log('hello');
};
this.stopWatch = new StopWatch(hello, 3000);
this.startBtn.addEventListener('click', this.start.bind(this));
this.stopBtn.addEventListener('click', this.stop.bind(this));
this.lapBtn.addEventListener('click', this.lap.bind(this));
this.resetBtn.addEventListener('click', this.reset.bind(this));
};
var stopWatchComponent = new StopWatchComponent();
</script>
</body>