-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.html
More file actions
185 lines (157 loc) · 6.11 KB
/
timer.html
File metadata and controls
185 lines (157 loc) · 6.11 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeRed '25</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="./css/timer.css">
</head>
<body>
<div id="particles-bg"></div>
<div class="hero-section">
<div class="header-text">EcellxBMSIT&M Presents</div>
<div class="title-container">
<span class="main-text">CODE RED</span><span class="year">'25</span>
</div>
<div class="tagline">Code Till You Drop.</div>
<h4>Hack harder, sleep later.</h4>
<div class="countdown">
<div class="time-block">
<p class="time-value" id="hours">25</p>
<p class="time-label">Hours</p>
</div>
<div class="time-block">
<p class="time-value" id="minutes">00</p>
<p class="time-label">Minutes</p>
</div>
<div class="time-block">
<p class="time-value" id="seconds">00</p>
<p class="time-label">Seconds</p>
</div>
</div>
<div class="progress-container">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
</div>
<div class="footer-text">Start Hacking!</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/particles.js/2.0.0/particles.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/baffle.js/0.3.6/baffle.min.js"></script>
<script src="./js/timer.js"></script>
<script>
class HackathonTimer {
constructor() {
const today = new Date();
this.startTime = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate()-1,
11, // 11 AM
0, // 0 minutes
0
).getTime();
this.duration = 25 * 60 * 60 * 1000; // 25 hours in milliseconds
this.endTime = this.startTime + this.duration;
this.elements = {
hours: document.getElementById('hours'),
minutes: document.getElementById('minutes'),
seconds: document.getElementById('seconds'),
progressFill: document.getElementById('progressFill'),
footerText: document.querySelector('.footer-text')
};
this.messages = [
{ timeOffset: 0, message: 'Start Hacking!' },
{ timeOffset: 2.5 * 3600000, message: 'Lunch Time!' },
{ timeOffset: 3.5 * 3600000, message: 'Continue Hacking!' },
{ timeOffset: 7 * 3600000, message: 'Phase 1 Evaluation' },
{ timeOffset: 8.5 * 3600000, message: 'Continue Hacking!' },
{ timeOffset: 9.5 * 3600000, message: 'Dinner Time!' },
{ timeOffset: 10.5 * 3600000, message: 'Continue Hacking!' },
{ timeOffset: 21 * 3600000, message: 'Breakfast Time!' },
{ timeOffset: 22 * 3600000, message: 'Final Sprint!' },
{ timeOffset: this.duration, message: "Time's Up!" }
];
this.initializeTimer();
}
initializeTimer() {
this.updateTimer();
setInterval(() => this.updateTimer(), 1000);
}
updateTimer() {
const now = new Date().getTime();
// Calculate elapsed and remaining time
let elapsedTime = now - this.startTime;
let remainingTime = this.endTime - now;
// If timer hasn't started yet
if (elapsedTime < 0) {
elapsedTime = 0;
remainingTime = this.duration;
this.elements.footerText.textContent = "Hackathon starts soon!";
this.updateProgress(0);
this.updateTimeDisplay(this.duration);
return;
}
// If timer is finished
if (remainingTime <= 0) {
this.handleTimeUp();
return;
}
// Calculate progress percentage
const progress = (elapsedTime / this.duration) * 100;
this.updateProgress(progress);
this.updateTimeDisplay(remainingTime);
this.updateMessage(elapsedTime);
}
updateProgress(progress) {
const clampedProgress = Math.max(0, Math.min(progress, 100));
requestAnimationFrame(() => {
this.elements.progressFill.style.width = `${clampedProgress}%`;
});
}
updateTimeDisplay(remainingTime) {
const hours = Math.floor(remainingTime / (1000 * 60 * 60));
const minutes = Math.floor((remainingTime % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((remainingTime % (1000 * 60)) / 1000);
this.elements.hours.textContent = String(hours).padStart(2, '0');
this.elements.minutes.textContent = String(minutes).padStart(2, '0');
this.elements.seconds.textContent = String(seconds).padStart(2, '0');
}
updateMessage(elapsedTime) {
const currentMessage = [...this.messages]
.reverse()
.find(msg => elapsedTime >= msg.timeOffset);
if (currentMessage) {
this.elements.footerText.textContent = currentMessage.message;
}
}
handleTimeUp() {
this.elements.hours.textContent = "00";
this.elements.minutes.textContent = "00";
this.elements.seconds.textContent = "00";
this.updateProgress(100);
this.elements.footerText.textContent = "Time's Up!";
}
}
document.addEventListener('DOMContentLoaded', () => {
new HackathonTimer();
const baffleOptions = {
characters: '▓▒░█ <>/[]{}'.split(''),
speed: 50
};
const mainText = baffle('.main-text', baffleOptions);
const yearText = baffle('.year', baffleOptions);
function animateText(element) {
element.start().reveal(2000, 800);
}
animateText(mainText);
animateText(yearText);
setInterval(() => {
animateText(mainText);
animateText(yearText);
}, 10000);
});
</script>
</body>
</html>