Skip to content

Commit 8b1724f

Browse files
committed
Agrego countdown
1 parent 114ddd6 commit 8b1724f

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

count_down/index.html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html lang="es">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Timer</title>
6+
<style>
7+
body {
8+
margin: 0;
9+
background: black;
10+
display: flex;
11+
justify-content: center;
12+
align-items: center;
13+
height: 100vh;
14+
font-family: monospace;
15+
}
16+
17+
.container {
18+
width: 100vw;
19+
height: 56.25vw; /* 16:9 ratio */
20+
max-height: 100vh;
21+
max-width: 177.78vh;
22+
display: flex;
23+
justify-content: center;
24+
align-items: center;
25+
}
26+
27+
#timer {
28+
font-size: 15vw;
29+
color: white;
30+
transition: color 0.3s;
31+
}
32+
33+
.overtime {
34+
color: red;
35+
animation: blink 1s infinite;
36+
}
37+
38+
@keyframes blink {
39+
0% { opacity: 1; }
40+
50% { opacity: 0.2; }
41+
100% { opacity: 1; }
42+
}
43+
</style>
44+
</head>
45+
<body>
46+
<div class="container">
47+
<div id="timer">01:00</div>
48+
</div>
49+
50+
<script>
51+
let countdown = 60; // segundos
52+
let overtime = 0;
53+
let isOvertime = false;
54+
55+
const timerEl = document.getElementById("timer");
56+
57+
function formatTime(seconds) {
58+
const m = String(Math.floor(seconds / 60)).padStart(2, '0');
59+
const s = String(seconds % 60).padStart(2, '0');
60+
return `${m}:${s}`;
61+
}
62+
63+
function update() {
64+
if (!isOvertime) {
65+
countdown--;
66+
timerEl.textContent = formatTime(countdown);
67+
68+
if (countdown <= 0) {
69+
isOvertime = true;
70+
timerEl.classList.add("overtime");
71+
}
72+
} else {
73+
overtime++;
74+
timerEl.textContent = formatTime(overtime);
75+
}
76+
}
77+
78+
// primer render
79+
timerEl.textContent = formatTime(countdown);
80+
81+
setInterval(update, 1000);
82+
</script>
83+
</body>
84+
</html>

0 commit comments

Comments
 (0)