File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments