-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule.html
59 lines (50 loc) · 1.41 KB
/
module.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Stopwatch</title>
<link rel="stylesheet" href="./css/app.css">
</head>
<body>
<div class="nav">
<a class="hoverHighlight" href="./index.html">< Back</a> | Stopwatch module
</div>
<div class="display">
<div id="timer">00:00:00:000</div>
<button type="button" id="start-button">Start</button>
<button type="button" id="stop-button">Stop</button>
</div>
<script src="./js/stopwatch.js"></script>
<script>
window.onload = function () {
var displayNode = document.getElementById("timer"),
displayInterval;
function onStart () {
Stopwatch.start();
if (!displayInterval) {
displayInterval = setInterval(updateDisplay, 25);
}
}
function updateDisplay () {
displayNode.innerHTML = Stopwatch.displayTime();
}
function onStop () {
if (Stopwatch.isRunning()) {
Stopwatch.stop();
}
else {
Stopwatch.reset();
updateDisplay();
}
if (!isNaN(displayInterval)) {
clearInterval(displayInterval);
displayInterval = null;
}
}
// connect buttons
document.getElementById("start-button").addEventListener("click", onStart);
document.getElementById("stop-button").addEventListener("click", onStop);
};
</script>
</body>
</html>