-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.html
75 lines (69 loc) · 2.67 KB
/
watch.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
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stopp Uhr</title>
<link rel="stylesheet" href="rain.css">
</head>
<body>
<canvas id='canv'></canvas>
<div class="container">
<div class="Top">
<header>
Jans Coding
</header>
</div>
<div class="Sidebar">
<a href="tags.html" effect="ripple">Tags</a><br><br>
<a href="about.html" effect="ripple">About</a> <br><br>
<a href="countdown.html" effect="ripple">Countdown</a> <br><br>
<a href="woodcutter.html" effect="ripple">My Game</a> <br><br>
<a href="aitools.html" effect="ripple">AI Tools</a>
</div>
<div class="Main">
<p style="font-family: 'emizen', sans-serif; font-size: 50px; text-align: center;">Stopuhr</p>
<div id="timer">00:00:000</div>
<button style="margin-left: 30%; font-family: 'emizen', sans-serif; font-size: 50px; text-align: center;"onclick="startTimer()">Start</button>
<button style="font-family: 'emizen', sans-serif; font-size: 50px; text-align: center;"onclick="stopTimer()">Stop</button>
<button style="font-family: 'emizen', sans-serif; font-size: 50px; text-align: center;"onclick="resetTimer()">Reset</button>
</div>
<div class="Bottom"></div>
</div>
<script>
let timerInterval;
let startTime;
let elapsedTime = 0;
function startTimer() {
startTime = Date.now() - elapsedTime;
timerInterval = setInterval(updateTimer, 1);
}
function stopTimer() {
clearInterval(timerInterval);
elapsedTime = Date.now() - startTime;
}
function resetTimer() {
clearInterval(timerInterval);
elapsedTime = 0;
updateTimer();
}
function updateTimer() {
const currentTime = Date.now();
const millisecondDiff = currentTime - startTime;
const hours = Math.floor(millisecondDiff / (1000 * 60 * 60));
const minutes = Math.floor((millisecondDiff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((millisecondDiff % (1000 * 60)) / 1000);
const milliseconds = Math.floor((millisecondDiff % 1000));
const formattedTime = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}:${pad(milliseconds, true)}`;
document.getElementById('timer').innerText = formattedTime;
}
function pad(value, isMilliseconds = false) {
if (isMilliseconds) {
return value < 10 ? '00' + value : value < 100 ? '0' + value : value;
}
return value < 10 ? '0' + value : value;
}
</script>
<script src="rain.js"></script>
</body>
</html>