-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
355 lines (299 loc) · 10.6 KB
/
script.js
File metadata and controls
355 lines (299 loc) · 10.6 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/**
* Eco Code Hackathon Website
* Interactive JavaScript functionality
*/
document.addEventListener('DOMContentLoaded', () => {
// Initialize all components
initNavigation();
initScrollEffects();
initScheduleTabs();
initFAQ();
initCountdown();
initStatsCounter();
initRevealAnimations();
initMouseGlow();
initParallax();
});
/**
* Navigation functionality
*/
function initNavigation() {
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('navToggle');
const navMenu = document.getElementById('navMenu');
const navLinks = document.querySelectorAll('.nav-link');
// Scroll effect for navbar
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Mobile menu toggle
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('active');
navMenu.classList.toggle('active');
document.body.style.overflow = navMenu.classList.contains('active') ? 'hidden' : '';
});
// Close menu when clicking a link
navLinks.forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = '';
});
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
}
/**
* Scroll-based effects
*/
function initScrollEffects() {
const scrollIndicator = document.querySelector('.scroll-indicator');
const heroContent = document.querySelector('.hero-content');
const heroTagline = document.querySelector('.hero-tagline'); // "Hack For The Planet"
// Hide scroll indicator on scroll
window.addEventListener('scroll', () => {
if (scrollIndicator) {
scrollIndicator.style.opacity = window.scrollY > 100 ? '0' : '1';
}
});
// Parallax effect for hero
const heroBg = document.querySelector('.hero-bg');
window.addEventListener('scroll', () => {
if (heroBg && window.scrollY < window.innerHeight) {
heroBg.style.transform = `translateY(${window.scrollY * 0.3}px)`;
}
});
// Hero content background fade-in on scroll
if (heroContent && heroTagline) {
const initialTaglineTop = heroTagline.getBoundingClientRect().top + window.scrollY;
window.addEventListener('scroll', () => {
// Start fading immediately on scroll, fully visible when tagline is at top
const scrollY = window.scrollY;
const endFade = initialTaglineTop - 80; // Fully faded in when tagline is 80px from top
let opacity = 0;
if (scrollY > 0) {
opacity = Math.min(1, scrollY / endFade);
}
heroContent.style.setProperty('--hero-bg-opacity', opacity);
}, { passive: true });
}
}
/**
* Schedule tabs functionality
*/
function initScheduleTabs() {
const tabs = document.querySelectorAll('.schedule-tab');
const days = document.querySelectorAll('.schedule-day');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
const targetDay = tab.dataset.day;
// Update active tab
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Update active day
days.forEach(day => {
day.classList.remove('active');
if (day.dataset.day === targetDay) {
day.classList.add('active');
}
});
});
});
}
/**
* FAQ accordion functionality
*/
function initFAQ() {
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
question.addEventListener('click', () => {
const isActive = item.classList.contains('active');
// Close all other items
faqItems.forEach(i => i.classList.remove('active'));
// Toggle current item
if (!isActive) {
item.classList.add('active');
}
});
});
}
/**
* Countdown timer
*
* TO ENABLE: Set a real deadline date below (format: 'YYYY-MM-DDTHH:MM:SS')
* Example: const deadline = new Date('2025-04-05T23:59:59').getTime();
*/
function initCountdown() {
// TODO: Set the actual deadline date when known
// const deadline = new Date('2025-04-05T23:59:59').getTime();
const deadline = null; // Set to null to show "TBD"
const daysEl = document.getElementById('days');
const hoursEl = document.getElementById('hours');
const minutesEl = document.getElementById('minutes');
const secondsEl = document.getElementById('seconds');
if (!daysEl || !hoursEl || !minutesEl || !secondsEl) return;
// If no deadline set, show TBD
if (!deadline) {
daysEl.textContent = 'TB';
hoursEl.textContent = 'D';
minutesEl.textContent = '--';
secondsEl.textContent = '--';
return;
}
function updateCountdown() {
const now = new Date().getTime();
const distance = deadline - now;
if (distance < 0) {
daysEl.textContent = '00';
hoursEl.textContent = '00';
minutesEl.textContent = '00';
secondsEl.textContent = '00';
return;
}
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
daysEl.textContent = String(days).padStart(2, '0');
hoursEl.textContent = String(hours).padStart(2, '0');
minutesEl.textContent = String(minutes).padStart(2, '0');
secondsEl.textContent = String(seconds).padStart(2, '0');
}
updateCountdown();
setInterval(updateCountdown, 1000);
}
/**
* Animated stats counter
*/
function initStatsCounter() {
const stats = document.querySelectorAll('.stat-number[data-count]');
const observerOptions = {
threshold: 0.5,
rootMargin: '0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
const target = parseInt(el.dataset.count);
animateCounter(el, target);
observer.unobserve(el);
}
});
}, observerOptions);
stats.forEach(stat => observer.observe(stat));
}
function animateCounter(element, target) {
const duration = 2000;
const start = 0;
const startTime = performance.now();
function updateCounter(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
// Easing function for smoother animation
const easeOutQuart = 1 - Math.pow(1 - progress, 4);
const current = Math.round(start + (target - start) * easeOutQuart);
element.textContent = current;
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
element.textContent = target + '+';
}
}
requestAnimationFrame(updateCounter);
}
/**
* Reveal animations on scroll
*/
function initRevealAnimations() {
const reveals = document.querySelectorAll('.section-header, .track-card, .prize-card, .special-card, .team-card, .faq-item, .timeline-item');
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// Add staggered delay based on index
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 50);
observer.unobserve(entry.target);
}
});
}, observerOptions);
reveals.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
}
/**
* Mouse glow effect for track cards
*/
function initMouseGlow() {
const cards = document.querySelectorAll('.track-card');
cards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = ((e.clientX - rect.left) / rect.width) * 100;
const y = ((e.clientY - rect.top) / rect.height) * 100;
card.style.setProperty('--mouse-x', `${x}%`);
card.style.setProperty('--mouse-y', `${y}%`);
});
});
}
/**
* Add floating leaves dynamically (optional enhancement)
*/
function addFloatingLeaves() {
const container = document.querySelector('.floating-leaves');
const emojis = ['🍃', '🌿', '🍂', '🌱', '🌾'];
setInterval(() => {
const leaf = document.createElement('div');
leaf.className = 'leaf';
leaf.textContent = emojis[Math.floor(Math.random() * emojis.length)];
leaf.style.left = `${Math.random() * 100}%`;
leaf.style.animationDuration = `${20 + Math.random() * 10}s`;
container.appendChild(leaf);
// Remove leaf after animation
setTimeout(() => {
leaf.remove();
}, 30000);
}, 5000);
}
// Uncomment to enable dynamic leaf generation
// addFloatingLeaves();
// Update copyright year
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
/**
* Parallax scrolling for background
*/
function initParallax() {
const canvas = document.getElementById('bg-canvas');
if (!canvas) return;
function updateParallax() {
document.documentElement.style.setProperty('--scroll-y', window.scrollY);
}
window.addEventListener('scroll', updateParallax, { passive: true });
updateParallax();
}