Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
220 lines (186 loc) · 7.71 KB
/
Copy pathscript.js
File metadata and controls
220 lines (186 loc) · 7.71 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* ============================================================
PORTAFOLIO PERSONAL — script.js
============================================================ */
document.addEventListener('DOMContentLoaded', () => {
/* ── 1. CURSOR PERSONALIZADO ──────────────────────────────── */
const cursor = document.getElementById('cursor');
const cursorDot = document.getElementById('cursorDot');
if (cursor && cursorDot) {
document.addEventListener('mousemove', (e) => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
cursorDot.style.left = e.clientX + 'px';
cursorDot.style.top = e.clientY + 'px';
});
document.addEventListener('mousedown', () => cursor.style.transform = 'translate(-50%, -50%) scale(0.8)');
document.addEventListener('mouseup', () => cursor.style.transform = 'translate(-50%, -50%) scale(1)');
}
/* ── 2. CANVAS HERO (partículas) ──────────────────────────── */
const canvas = document.getElementById('heroCanvas');
if (canvas) {
const ctx = canvas.getContext('2d');
let particles = [];
let animId;
const resize = () => {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
};
resize();
window.addEventListener('resize', resize);
class Particle {
constructor() { this.reset(); }
reset() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.vx = (Math.random() - 0.5) * 0.4;
this.vy = (Math.random() - 0.5) * 0.4;
this.r = Math.random() * 1.5 + 0.5;
this.alpha = Math.random() * 0.5 + 0.1;
}
update() {
this.x += this.vx;
this.y += this.vy;
if (this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height) {
this.reset();
}
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
ctx.fillStyle = `rgba(200, 241, 53, ${this.alpha})`;
ctx.fill();
}
}
const N = 80;
for (let i = 0; i < N; i++) particles.push(new Particle());
const drawLines = () => {
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 100) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = `rgba(200, 241, 53, ${0.06 * (1 - dist / 100)})`;
ctx.lineWidth = 0.5;
ctx.stroke();
}
}
}
};
const loop = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => { p.update(); p.draw(); });
drawLines();
animId = requestAnimationFrame(loop);
};
loop();
}
/* ── 3. NAVBAR: scroll + active link ─────────────────────── */
const navbar = document.getElementById('navbar');
const navLinks = document.querySelectorAll('.nav__link');
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => {
// Fondo del nav al hacer scroll
navbar.classList.toggle('scrolled', window.scrollY > 20);
// Active link según sección visible
let current = '';
sections.forEach(sec => {
const top = sec.offsetTop - 120;
if (window.scrollY >= top) current = sec.getAttribute('id');
});
navLinks.forEach(link => {
const href = link.getAttribute('href').replace('#', '');
link.classList.toggle('active', href === current);
});
});
/* ── 4. MENÚ MOBILE ───────────────────────────────────────── */
const menuBtn = document.getElementById('menuBtn');
const mobileMenu = document.getElementById('mobileMenu');
const mobileLinks = document.querySelectorAll('.mobile-link');
if (menuBtn && mobileMenu) {
menuBtn.addEventListener('click', () => {
mobileMenu.classList.toggle('open');
const spans = menuBtn.querySelectorAll('span');
const isOpen = mobileMenu.classList.contains('open');
// Animación hamburguesa → X
if (isOpen) {
spans[0].style.transform = 'translateY(6.5px) rotate(45deg)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'translateY(-6.5px) rotate(-45deg)';
} else {
spans.forEach(s => { s.style.transform = ''; s.style.opacity = ''; });
}
});
mobileLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('open');
const spans = menuBtn.querySelectorAll('span');
spans.forEach(s => { s.style.transform = ''; s.style.opacity = ''; });
});
});
}
/* ── 5. SCROLL REVEAL ─────────────────────────────────────── */
const revealEls = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
// Efecto escalonado entre elementos hermanos
const siblings = [...entry.target.parentElement.children];
const index = siblings.indexOf(entry.target);
entry.target.style.transitionDelay = `${index * 80}ms`;
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
revealEls.forEach(el => revealObserver.observe(el));
/* ── 7. FILTRO DE PROYECTOS ───────────────────────────────── */
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
const filter = btn.dataset.filter;
// Botón activo
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// Mostrar / ocultar cards
projectCards.forEach(card => {
const cat = card.dataset.category;
if (filter === 'all' || cat === filter) {
card.classList.remove('hidden');
// Pequeña animación de reentrada
card.style.animation = 'none';
card.offsetHeight; // reflow
card.style.animation = 'fadeInCard 0.4s ease forwards';
} else {
card.classList.add('hidden');
}
});
});
});
// Keyframe para el filtro
const style = document.createElement('style');
style.textContent = `
@keyframes fadeInCard {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: translateY(0); }
}
`;
document.head.appendChild(style);
/* ── 8. AÑO ACTUAL EN FOOTER ──────────────────────────────── */
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
/* ── 9. SMOOTH SCROLL (fallback para navegadores antiguos) ── */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', (e) => {
const target = document.querySelector(anchor.getAttribute('href'));
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});
});