-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (40 loc) · 1.87 KB
/
Copy pathscript.js
File metadata and controls
48 lines (40 loc) · 1.87 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
const header = document.querySelector('.site-header');
const menuButton = document.querySelector('.menu-toggle');
const navigation = document.querySelector('.main-nav');
const navLinks = [...document.querySelectorAll('.main-nav a[href^="#"]')];
const sections = [...document.querySelectorAll('main section[id]')];
document.getElementById('current-year').textContent = new Date().getFullYear();
function closeMenu() {
navigation.classList.remove('open');
menuButton.setAttribute('aria-expanded', 'false');
menuButton.setAttribute('aria-label', 'Abrir menu');
document.body.classList.remove('menu-open');
}
menuButton.addEventListener('click', () => {
const willOpen = !navigation.classList.contains('open');
navigation.classList.toggle('open', willOpen);
menuButton.setAttribute('aria-expanded', String(willOpen));
menuButton.setAttribute('aria-label', willOpen ? 'Fechar menu' : 'Abrir menu');
document.body.classList.toggle('menu-open', willOpen);
});
navigation.querySelectorAll('a').forEach(link => link.addEventListener('click', closeMenu));
function updateHeader() {
header.classList.toggle('scrolled', window.scrollY > 40);
let current = 'inicio';
for (const section of sections) {
if (window.scrollY >= section.offsetTop - 160) current = section.id;
}
navLinks.forEach(link => link.classList.toggle('active', link.getAttribute('href') === `#${current}`));
}
const revealObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
document.querySelectorAll('.reveal').forEach(element => revealObserver.observe(element));
window.addEventListener('scroll', updateHeader, { passive: true });
window.addEventListener('resize', () => { if (window.innerWidth > 980) closeMenu(); });
updateHeader();