-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
221 lines (188 loc) · 9.25 KB
/
Copy pathscript.js
File metadata and controls
221 lines (188 loc) · 9.25 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
/* ═══════════════════════════════════════════════════════════════
PROJECT HELIA — script.js
Countdown · Navbar · Carousels · Mission tabs · Stats · Reveal
══════════════════════════════════════════════════════════════ */
document.addEventListener('DOMContentLoaded', () => {
initNavbar();
initCountdown();
initMissionTabs();
initSubsectionNavs();
initCarousels();
initStatsCounter();
initScrollReveal();
initAltitudeAnimation();
});
/* ─────────────────────────────────────────────────────────────
NAVBAR — background on scroll
─────────────────────────────────────────────────────────── */
function initNavbar() {
const nav = document.getElementById('navbar');
const onScroll = () => {
nav.classList.toggle('scrolled', window.scrollY > 40);
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
/* ─────────────────────────────────────────────────────────────
COUNTDOWN — T- to 15 Oct 2026 08:00 UTC
─────────────────────────────────────────────────────────── */
function initCountdown() {
const display = document.getElementById('countdown-display');
if (!display) return;
const launch = new Date('2026-10-15T08:00:00Z').getTime();
function pad(n, w = 2) {
return String(Math.floor(n)).padStart(w, '0');
}
function tick() {
const now = Date.now();
const diff = launch - now;
if (diff <= 0) {
display.textContent = '00d 00h 00m 00s';
return;
}
const d = Math.floor(diff / 86400000);
const h = Math.floor((diff % 86400000) / 3600000);
const m = Math.floor((diff % 3600000) / 60000);
const s = Math.floor((diff % 60000) / 1000);
display.textContent = `${pad(d, 3)}d ${pad(h)}h ${pad(m)}m ${pad(s)}s`;
}
tick();
setInterval(tick, 1000);
}
/* ─────────────────────────────────────────────────────────────
MISSION TABS
─────────────────────────────────────────────────────────── */
function initMissionTabs() {
const buttons = document.querySelectorAll('.tab-btn');
const panels = document.querySelectorAll('.tab-panel');
buttons.forEach(btn => {
btn.addEventListener('click', () => {
const target = btn.dataset.tab;
buttons.forEach(b => {
b.classList.remove('active');
b.setAttribute('aria-selected', 'false');
});
panels.forEach(p => p.classList.remove('active'));
btn.classList.add('active');
btn.setAttribute('aria-selected', 'true');
const panel = document.getElementById(`tab-${target}`);
if (panel) {
panel.classList.add('active');
// Trigger altitude path animation when flight tab opens
if (target === 'flight') {
requestAnimationFrame(() => {
const path = document.getElementById('altitude-path');
if (path) path.classList.add('drawn');
});
}
}
});
});
}
/* ─────────────────────────────────────────────────────────────
SUBSECTION NAVS (Science / Tech)
─────────────────────────────────────────────────────────── */
function initSubsectionNavs() {
// Each section has its own subsection-nav + subsection panels
document.querySelectorAll('#the-science, #the-tech').forEach(section => {
const nav = section.querySelector('.subsection-nav');
const buttons = nav ? nav.querySelectorAll('.subsection-btn') : [];
const subsections = section.querySelectorAll('.subsection');
buttons.forEach(btn => {
btn.addEventListener('click', () => {
const target = btn.dataset.subsection;
buttons.forEach(b => b.classList.remove('active'));
subsections.forEach(s => s.classList.remove('active'));
btn.classList.add('active');
const sub = section.querySelector(`#sub-${target}`);
if (sub) sub.classList.add('active');
});
});
});
}
/* ─────────────────────────────────────────────────────────────
CAROUSELS
─────────────────────────────────────────────────────────── */
function initCarousels() {
document.querySelectorAll('.carousel').forEach(carousel => {
const slides = carousel.querySelectorAll('.carousel-slide');
const buttons = carousel.querySelectorAll('.c-btn');
function goTo(index) {
slides.forEach((s, i) => s.classList.toggle('active', i === index));
buttons.forEach((b, i) => b.classList.toggle('active', i === index));
}
buttons.forEach((btn, i) => {
btn.addEventListener('click', () => goTo(i));
});
// Optional: keyboard arrow support when focused within carousel
carousel.addEventListener('keydown', e => {
const activeSlide = [...slides].findIndex(s => s.classList.contains('active'));
if (e.key === 'ArrowRight' && activeSlide < slides.length - 1) goTo(activeSlide + 1);
if (e.key === 'ArrowLeft' && activeSlide > 0) goTo(activeSlide - 1);
});
});
}
/* ─────────────────────────────────────────────────────────────
STATS COUNTER — counts up when scrolled into view
─────────────────────────────────────────────────────────── */
function initStatsCounter() {
const nums = document.querySelectorAll('.stat-num');
if (!nums.length) return;
function animateCount(el) {
if (el.dataset.counted) return;
el.dataset.counted = 'true';
const target = parseInt(el.dataset.target, 10);
const duration = 1800;
const start = performance.now();
function step(now) {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
// ease out cubic
const eased = 1 - Math.pow(1 - progress, 3);
el.textContent = Math.round(eased * target);
if (progress < 1) requestAnimationFrame(step);
}
requestAnimationFrame(step);
}
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
animateCount(entry.target);
}
});
}, { threshold: 0.5 });
nums.forEach(n => observer.observe(n));
}
/* ─────────────────────────────────────────────────────────────
SCROLL REVEAL — fade + rise on elements with .reveal
─────────────────────────────────────────────────────────── */
function initScrollReveal() {
const els = document.querySelectorAll('.reveal');
if (!els.length) return;
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' });
els.forEach(el => observer.observe(el));
}
/* ─────────────────────────────────────────────────────────────
ALTITUDE SVG — animate path when The Flight tab is opened
Also auto-draw if it's visible in viewport (in case already open)
─────────────────────────────────────────────────────────── */
function initAltitudeAnimation() {
const path = document.getElementById('altitude-path');
if (!path) return;
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
path.classList.add('drawn');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.3 });
observer.observe(path);
}