-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
90 lines (83 loc) · 2.95 KB
/
Copy pathindex.html
File metadata and controls
90 lines (83 loc) · 2.95 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
90
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Controle de Tempo</title>
</head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Jaro:opsz@6..72&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="style.css" />
<body>
<h2 id="relogio"></h2>
<script>
function atualizarRelogio() {
const agora = new Date();
const horas = agora.getHours().toString().padStart(2, "0");
const minutos = agora.getMinutes().toString().padStart(2, "0");
const segundos = agora.getSeconds().toString().padStart(2, "0");
document.getElementById(
"relogio"
).innerText = `${horas}:${minutos}:${segundos}`;
document.getElementById("agora").innerText = `${agora}`;
}
setInterval(atualizarRelogio, 1000);
atualizarRelogio();
</script>
<hr />
<h2 id="cronometro">00:00:00</h2>
<div>
<button onclick="iniciar()" id="btIniciar">Iniciar</button>
<button onclick="pausar()" id="btPausar">Pausar</button>
<button onclick="zerar()" id="btZerar">Zerar</button>
</div>
<script>
let segundos = 0;
let intervalo;
function formatarTime(segundos) {
const h = String(Math.floor(segundos / 3600)).padStart(2, "0");
const m = String(Math.floor((segundos % 3600) / 60)).padStart(2, "0");
const s = String(segundos % 60).padStart(2, "0");
return `${h}:${m}:${s}`;
}
function atualizarCronometro() {
document.getElementById("cronometro").innerText =
formatarTime(segundos);
}
function iniciar() {
if (!intervalo) {
intervalo = setInterval(() => {
segundos++;
atualizarCronometro();
}, 1000);
document.getElementById("btIniciar").innerText = "Iniciar";
document.getElementById("btIniciar").disabled = true;
}
}
function pausar() {
if (intervalo) {
clearInterval(intervalo);
intervalo = null;
document.getElementById("btPausar").innerText = "Retomar";
document.getElementById("btIniciar").disabled = true;
} else {
iniciar();
document.getElementById("btPausar").innerText = "Pausar";
}
}
function zerar() {
clearInterval(intervalo);
intervalo = null;
segundos = 0;
atualizarCronometro();
document.getElementById("btIniciar").innerText = "Iniciar";
document.getElementById("btPausar").innerText = "Pausar";
document.getElementById("btIniciar").disabled = false;
}
</script>
</body>
</html>