-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (56 loc) · 1.88 KB
/
script.js
File metadata and controls
69 lines (56 loc) · 1.88 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
// ============ MOBILE NAV TOGGLE ============
const navToggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
navToggle.addEventListener('click', () => {
navLinks.classList.toggle('open');
});
// Close mobile nav on link click
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
});
});
// ============ ACTIVE NAV HIGHLIGHTING ============
const sections = document.querySelectorAll('section[id]');
const navAnchors = document.querySelectorAll('.nav-links a');
function updateActiveNav() {
const scrollY = window.scrollY + 120;
sections.forEach(section => {
const top = section.offsetTop;
const height = section.offsetHeight;
const id = section.getAttribute('id');
if (scrollY >= top && scrollY < top + height) {
navAnchors.forEach(a => {
a.classList.remove('active');
if (a.getAttribute('href') === '#' + id) {
a.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', updateActiveNav, { passive: true });
updateActiveNav();
// ============ ACCORDION ============
document.querySelectorAll('.acc-header').forEach(header => {
header.addEventListener('click', () => {
const item = header.parentElement;
const wasOpen = item.classList.contains('open');
// Close all
document.querySelectorAll('.acc-item').forEach(i => i.classList.remove('open'));
// Toggle clicked
if (!wasOpen) {
item.classList.add('open');
}
});
});
// ============ NAV BACKGROUND ON SCROLL ============
const nav = document.getElementById('nav');
function updateNavBg() {
if (window.scrollY > 50) {
nav.style.borderBottomColor = 'rgba(0, 212, 170, 0.15)';
} else {
nav.style.borderBottomColor = '';
}
}
window.addEventListener('scroll', updateNavBg, { passive: true });