-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
291 lines (252 loc) · 10.3 KB
/
Copy pathmain.js
File metadata and controls
291 lines (252 loc) · 10.3 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
// ===== LOADER =====
window.addEventListener('load', () => {
const loader = document.getElementById('loader');
const bar = document.getElementById('loaderBar');
const hero = document.getElementById('hero');
// Extend the bar to full width
requestAnimationFrame(() => {
bar.style.width = '100%';
});
// Done: fade out loader, trigger hero reveal
setTimeout(() => {
loader.classList.add('done');
hero.classList.add('hero-animate');
}, 620);
});
// ===== NAVIGATION =====
const nav = document.getElementById('nav');
const heroEl = document.getElementById('hero');
// Show nav when hero scrolls out of view
const heroObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
nav.classList.toggle('visible', !entry.isIntersecting);
});
}, { threshold: 0.1 });
heroObserver.observe(heroEl);
// Add frosted-glass background after a small scroll
window.addEventListener('scroll', () => {
nav.classList.toggle('scrolled', window.scrollY > 40);
}, { passive: true });
// ===== SECTION FADE-IN ON SCROLL =====
const fadeObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
fadeObserver.unobserve(entry.target);
}
});
}, {
threshold: 0.08,
rootMargin: '0px 0px -48px 0px'
});
document.querySelectorAll('.fade-section').forEach(el => {
fadeObserver.observe(el);
});
// ===== HOBBY MODAL =====
// To add photos later, add objects to each array:
// { src: 'images/hobbies/lego/photo1.jpg', caption: 'Optional caption' }
const hobbyPhotos = {
drama: [],
film: [],
lego: [],
miniature: [],
piano: [],
comics: [],
tcg: [],
travel: [],
};
const hobbyLabels = {
drama: 'Drama',
film: 'Film',
lego: 'LEGO',
miniature: 'Miniature Painting',
piano: 'Piano',
comics: 'Comics',
tcg: 'TCG',
travel: 'Travel',
};
const modal = document.getElementById('hobbyModal');
const overlay = document.getElementById('modalOverlay');
const closeBtn = document.getElementById('modalClose');
const modalTitle = document.getElementById('modalTitle');
const photoGrid = document.getElementById('photoGrid');
const emptyState = document.getElementById('modalEmpty');
function openModal(hobby) {
modalTitle.textContent = hobbyLabels[hobby] || hobby;
const photos = hobbyPhotos[hobby] || [];
photoGrid.innerHTML = '';
if (photos.length > 0) {
emptyState.style.display = 'none';
photos.forEach(({ src, caption }) => {
const img = document.createElement('img');
img.src = src;
img.alt = caption || hobbyLabels[hobby];
img.loading = 'lazy';
photoGrid.appendChild(img);
});
} else {
emptyState.style.display = 'flex';
}
modal.classList.add('open');
modal.setAttribute('aria-hidden', 'false');
document.body.style.overflow = 'hidden';
}
function closeModal() {
modal.classList.remove('open');
modal.setAttribute('aria-hidden', 'true');
document.body.style.overflow = '';
}
document.querySelectorAll('.hobby-card').forEach(card => {
card.addEventListener('click', () => openModal(card.dataset.hobby));
});
overlay.addEventListener('click', closeModal);
closeBtn.addEventListener('click', closeModal);
document.addEventListener('keydown', e => {
if (e.key === 'Escape') closeModal();
});
// ===== TRAVEL MAP =====
(async function () {
const VISITED = new Set([156, 158, 458, 702, 392, 462]); // China+Taiwan, Malaysia, Singapore, Japan, Maldives
const CITIES = [
// China
{ name: 'Wuhan', lon: 114.306, lat: 30.593, rooted: true },
{ name: 'Xuzhou', lon: 117.186, lat: 34.261 },
{ name: 'Enshi', lon: 109.466, lat: 30.272 },
{ name: 'Xianning', lon: 114.322, lat: 29.853 },
{ name: 'Ezhou', lon: 114.894, lat: 30.391 },
{ name: 'Beijing', lon: 116.407, lat: 39.904, rooted: true },
{ name: 'Shanghai', lon: 121.474, lat: 31.230, rooted: true },
{ name: 'Guangzhou', lon: 113.264, lat: 23.129 },
{ name: 'Shenzhen', lon: 114.058, lat: 22.543 },
{ name: 'Hangzhou', lon: 120.155, lat: 30.274 },
{ name: 'Chengdu', lon: 104.067, lat: 30.573 },
{ name: 'Sanya', lon: 109.512, lat: 18.253 },
{ name: 'Baotou', lon: 109.840, lat: 40.657 },
{ name: 'Hohhot', lon: 111.749, lat: 40.843 },
{ name: 'Weihai', lon: 122.114, lat: 37.513 },
{ name: 'Yantai', lon: 121.448, lat: 37.464 },
{ name: 'Jiuzhaigou', lon: 103.919, lat: 33.260 },
{ name: 'Hong Kong', lon: 114.169, lat: 22.319 },
{ name: 'Zhoukou', lon: 114.653, lat: 33.648 },
{ name: 'Nanchang', lon: 115.858, lat: 28.682 },
{ name: 'Jiujiang', lon: 115.993, lat: 29.706 },
{ name: 'Kunming', lon: 102.718, lat: 25.039 },
{ name: 'Dali', lon: 100.268, lat: 25.607 },
{ name: 'Xiamen', lon: 118.089, lat: 24.480 },
// Malaysia
{ name: 'Kuala Lumpur', lon: 101.687, lat: 3.139, rooted: true },
{ name: 'Penang', lon: 100.329, lat: 5.414 },
{ name: 'Malacca', lon: 102.250, lat: 2.190 },
{ name: 'Johor Bahru', lon: 103.741, lat: 1.493 },
// Singapore
{ name: 'Singapore', lon: 103.820, lat: 1.352 },
// Japan
{ name: 'Kyoto', lon: 135.768, lat: 35.012, rooted: true },
{ name: 'Osaka', lon: 135.502, lat: 34.694 },
{ name: 'Otsu', lon: 135.869, lat: 35.005 },
{ name: 'Tokyo', lon: 139.650, lat: 35.676, rooted: true },
{ name: 'Inatori', lon: 139.039, lat: 34.745 },
{ name: 'Sapporo', lon: 141.355, lat: 43.062 },
{ name: 'Monbetsu', lon: 143.354, lat: 44.356 },
{ name: 'Noboribetsu', lon: 141.103, lat: 42.413 },
{ name: 'Kobe', lon: 135.196, lat: 34.690 },
{ name: 'Gotemba', lon: 138.934, lat: 35.308 },
// Maldives
{ name: 'Malé', lon: 73.509, lat: 4.176 },
{ name: 'Kuramathi', lon: 72.900, lat: 4.267 },
];
const svgEl = document.getElementById('travel-map');
if (!svgEl) return;
const W = 960, H = 500;
const svg = d3.select(svgEl).attr('viewBox', `0 0 ${W} ${H}`);
const projection = d3.geoNaturalEarth1()
.scale(155)
.translate([W / 2, H / 2 + 20]);
const path = d3.geoPath().projection(projection);
const tooltip = document.getElementById('mapTooltip');
const mapWrap = svgEl.closest('.map-wrap');
try {
const world = await d3.json('https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json');
const countries = topojson.feature(world, world.objects.countries);
// Subtle graticule grid
svg.append('path')
.datum(d3.geoGraticule()())
.attr('d', path)
.attr('fill', 'none')
.attr('stroke', '#C8D8E2')
.attr('stroke-width', 0.3);
// All countries
svg.selectAll('.country')
.data(countries.features)
.enter().append('path')
.attr('class', 'country')
.attr('d', path)
.attr('fill', d => VISITED.has(+d.id) ? 'rgba(155,123,90,0.22)' : 'var(--tag-bg)')
.attr('stroke', 'var(--border)')
.attr('stroke-width', 0.5);
// Accent border on visited countries
svg.selectAll('.country-hi')
.data(countries.features.filter(d => VISITED.has(+d.id)))
.enter().append('path')
.attr('d', path)
.attr('fill', 'none')
.attr('stroke', 'var(--accent)')
.attr('stroke-width', 1)
.attr('opacity', 0.5);
// Rooted city outer rings (drawn first, behind the fill dot)
svg.selectAll('.city-ring')
.data(CITIES.filter(d => d.rooted))
.enter().append('circle')
.attr('cx', d => projection([d.lon, d.lat])[0])
.attr('cy', d => projection([d.lon, d.lat])[1])
.attr('r', 6.5)
.attr('fill', 'none')
.attr('stroke', '#5C3D20')
.attr('stroke-width', 1)
.attr('opacity', 0.45);
// City dots
svg.selectAll('.city-dot')
.data(CITIES)
.enter().append('circle')
.attr('class', 'city-dot')
.attr('cx', d => projection([d.lon, d.lat])[0])
.attr('cy', d => projection([d.lon, d.lat])[1])
.attr('r', d => d.rooted ? 4 : 2.5)
.attr('fill', d => d.rooted ? '#5C3D20' : 'var(--accent)')
.attr('stroke', 'var(--bg)')
.attr('stroke-width', 1)
.attr('opacity', 0.9)
.on('mouseover', function (event, d) {
d3.select(this).attr('r', d.rooted ? 5.5 : 4).attr('opacity', 1);
if (tooltip) {
tooltip.textContent = d.name;
tooltip.style.opacity = '1';
}
})
.on('mousemove', function (event) {
if (!tooltip || !mapWrap) return;
const rect = mapWrap.getBoundingClientRect();
tooltip.style.left = (event.clientX - rect.left + 12) + 'px';
tooltip.style.top = (event.clientY - rect.top - 32) + 'px';
})
.on('mouseout', function (event, d) {
d3.select(this).attr('r', d.rooted ? 4 : 2.5).attr('opacity', 0.9);
if (tooltip) tooltip.style.opacity = '0';
});
} catch (e) {
console.error('Map failed to load:', e);
}
})();
// ===== SMOOTH ANCHOR SCROLL =====
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', e => {
const id = anchor.getAttribute('href');
const target = document.querySelector(id);
if (target) {
e.preventDefault();
const offset = 72; // nav height
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});