Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (44 loc) · 1.63 KB
/
Copy pathapp.js
File metadata and controls
49 lines (44 loc) · 1.63 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
// IMGA SLP — client-side router & interactions
(function () {
const pages = document.querySelectorAll('.page');
const links = document.querySelectorAll('[data-nav]');
function showPage(id) {
const target = document.getElementById(id) || document.getElementById('inicio');
pages.forEach(p => p.classList.toggle('active', p === target));
links.forEach(a => {
const href = a.getAttribute('href') || '';
a.classList.toggle('active', href === '#' + target.id);
});
window.scrollTo({ top: 0, behavior: 'instant' });
// close mobile menu
document.getElementById('mobile-menu')?.classList.remove('open');
document.getElementById('burger')?.classList.remove('open');
document.body.style.overflow = '';
}
function route() {
const hash = (location.hash || '#inicio').replace('#', '');
showPage(hash);
}
window.addEventListener('hashchange', route);
window.addEventListener('DOMContentLoaded', () => {
route();
// burger
const burger = document.getElementById('burger');
const menu = document.getElementById('mobile-menu');
burger?.addEventListener('click', () => {
burger.classList.toggle('open');
menu.classList.toggle('open');
document.body.style.overflow = menu.classList.contains('open') ? 'hidden' : '';
});
// reveal on scroll
const io = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('in');
io.unobserve(e.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.reveal').forEach(el => io.observe(el));
});
})();