-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (74 loc) · 2.94 KB
/
Copy pathscript.js
File metadata and controls
86 lines (74 loc) · 2.94 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
// ============================================================
// NELSON OROZCO — script.js
// Nav con blur al hacer scroll, reveal on scroll, barras de
// habilidades animadas, menú móvil, navegación activa.
// ============================================================
document.addEventListener('DOMContentLoaded', () => {
// Año en el footer
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
// Nav: fondo con blur al hacer scroll
const nav = document.getElementById('nav');
const onScroll = () => {
if (window.scrollY > 12) nav.classList.add('scrolled');
else nav.classList.remove('scrolled');
};
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
// Menú móvil
const navToggle = document.getElementById('navToggle');
const navLinks = document.getElementById('navLinks');
if (navToggle && navLinks) {
navToggle.addEventListener('click', () => {
const isOpen = navLinks.classList.toggle('open');
navToggle.setAttribute('aria-expanded', String(isOpen));
});
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
navToggle.setAttribute('aria-expanded', 'false');
});
});
}
// Scroll-reveal
const revealEls = document.querySelectorAll('.reveal');
if ('IntersectionObserver' in window && revealEls.length) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
// Si el elemento contiene barras de habilidades, animarlas
entry.target.querySelectorAll('.bar-fill').forEach(bar => {
requestAnimationFrame(() => bar.classList.add('filled'));
});
observer.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
revealEls.forEach(el => observer.observe(el));
} else {
revealEls.forEach(el => {
el.classList.add('in-view');
el.querySelectorAll('.bar-fill').forEach(bar => bar.classList.add('filled'));
});
}
// Navegación activa según sección visible
const navAnchors = document.querySelectorAll('[data-nav]');
const sections = Array.from(navAnchors)
.map(link => document.querySelector(link.getAttribute('href')))
.filter(Boolean);
if ('IntersectionObserver' in window && sections.length) {
const navObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
const id = '#' + entry.target.id;
const link = document.querySelector(`[data-nav][href="${id}"]`);
if (!link) return;
if (entry.isIntersecting) {
navAnchors.forEach(l => l.classList.remove('active'));
link.classList.add('active');
}
});
}, { rootMargin: '-40% 0px -50% 0px' });
sections.forEach(sec => navObserver.observe(sec));
}
});