-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.58 KB
/
script.js
File metadata and controls
44 lines (37 loc) · 1.58 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
document.addEventListener('DOMContentLoaded', function () {
// ── Hamburger menu (legacy, kept for compatibility) ──
const icon = document.querySelector('.hamburger i');
const mobile = document.querySelector('.mobile');
if (icon && mobile) {
icon.addEventListener('click', function () {
mobile.style.display = mobile.style.display === 'none' ? 'inherit' : 'none';
});
}
// ── Scroll snap nav dots ──
const container = document.getElementById('snap-container');
const dotRows = document.querySelectorAll('.dot-row');
const sections = document.querySelectorAll('.snap-section');
const sectionLabel = document.getElementById('section-label');
if (!container || !dotRows.length || !sections.length) return;
// Click dot to jump to section
dotRows.forEach(function (row) {
row.addEventListener('click', function () {
const index = parseInt(row.dataset.index);
sections[index].scrollIntoView({ behavior: 'smooth' });
});
});
// Update active dot and section label on scroll
const observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
const index = Array.from(sections).indexOf(entry.target);
dotRows.forEach(function (r) { r.classList.remove('active'); });
dotRows[index].classList.add('active');
if (sectionLabel) {
sectionLabel.textContent = dotRows[index].dataset.label;
}
}
});
}, { root: container, threshold: 0.5 });
sections.forEach(function (section) { observer.observe(section); });
});