-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
439 lines (364 loc) · 16.6 KB
/
Copy pathscripts.js
File metadata and controls
439 lines (364 loc) · 16.6 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
// Animación de escritura para el nombre
const nameElement = document.querySelector('header h1');
const originalText = nameElement.textContent;
nameElement.textContent = '';
let charIndex = 0;
function typeWriter() {
if (charIndex < originalText.length) {
nameElement.textContent += originalText.charAt(charIndex);
charIndex++;
setTimeout(typeWriter, 100);
}
}
setTimeout(typeWriter, 500);
// Animación de aparición al hacer scroll
const observerOptions = {
threshold: 0.2,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '0';
entry.target.style.transform = 'translateY(30px)';
setTimeout(() => {
entry.target.style.transition = 'opacity 0.8s, transform 0.8s';
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, 100);
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
// Animación de las skill cards al aparecer
const skillCards = document.querySelectorAll('.skill-category');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '0';
entry.target.style.transform = 'scale(0.8)';
setTimeout(() => {
entry.target.style.transition = 'all 0.5s ease-out';
entry.target.style.opacity = '1';
entry.target.style.transform = 'scale(1)';
}, 50);
}, index * 150);
skillObserver.unobserve(entry.target);
}
});
}, observerOptions);
skillCards.forEach(card => skillObserver.observe(card));
// Animación de las project cards
const projectCards = document.querySelectorAll('.project-card');
const projectObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '0';
entry.target.style.transform = 'translateX(-50px) rotateY(-15deg)';
setTimeout(() => {
entry.target.style.transition = 'all 0.6s ease-out';
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateX(0) rotateY(0)';
}, 50);
}, index * 120);
projectObserver.unobserve(entry.target);
}
});
}, observerOptions);
projectCards.forEach(card => projectObserver.observe(card));
// Animación de las certification cards
const certCards = document.querySelectorAll('.certification-card');
const certObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '0';
entry.target.style.transform = 'scale(0.5) rotate(-5deg)';
setTimeout(() => {
entry.target.style.transition = 'all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55)';
entry.target.style.opacity = '1';
entry.target.style.transform = 'scale(1) rotate(0)';
}, 50);
}, index * 200);
certObserver.unobserve(entry.target);
}
});
}, observerOptions);
certCards.forEach(card => certObserver.observe(card));
// Efecto parallax en el fondo
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('section');
parallaxElements.forEach(el => {
const speed = 0.5;
const yPos = -(scrolled * speed);
el.style.backgroundPosition = `center ${yPos}px`;
});
ticking = false;
});
ticking = true;
}
});
// Smooth scroll para los links de navegación
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
});
});
// Animación de contador para los años de experiencia
const experienceItems = document.querySelectorAll('.experience-item');
experienceItems.forEach(item => {
item.addEventListener('mouseenter', function() {
this.style.transform = 'translateX(10px)';
this.style.transition = 'transform 0.3s ease';
});
item.addEventListener('mouseleave', function() {
this.style.transform = 'translateX(0)';
});
});
// Efecto de brillo en las skill tags al pasar el mouse
const tags = document.querySelectorAll('.tag');
tags.forEach(tag => {
tag.addEventListener('mouseenter', function() {
this.style.boxShadow = '0 0 15px rgba(59, 130, 246, 0.6)';
this.style.transform = 'scale(1.1)';
this.style.transition = 'all 0.3s ease';
});
tag.addEventListener('mouseleave', function() {
this.style.boxShadow = 'none';
this.style.transform = 'scale(1)';
});
});
// Animación de partículas en el fondo (efecto sutil)
const canvas = document.createElement('canvas');
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.width = '100%';
canvas.style.height = '100%';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '0';
document.body.insertBefore(canvas, document.body.firstChild);
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const particles = [];
const particleCount = 50;
class Particle {
constructor() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.size = Math.random() * 2 + 1;
this.speedX = Math.random() * 0.5 - 0.25;
this.speedY = Math.random() * 0.5 - 0.25;
this.opacity = Math.random() * 0.5 + 0.2;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x > canvas.width) this.x = 0;
if (this.x < 0) this.x = canvas.width;
if (this.y > canvas.height) this.y = 0;
if (this.y < 0) this.y = canvas.height;
}
draw() {
ctx.fillStyle = `rgba(59, 130, 246, ${this.opacity})`;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle());
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(particle => {
particle.update();
particle.draw();
});
requestAnimationFrame(animateParticles);
}
animateParticles();
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
// Animación del carrusel de proyectos
document.addEventListener("DOMContentLoaded", () => {
const track = document.querySelector(".carousel-track");
const cards = Array.from(track.children);
const prevButton = document.querySelector(".carousel-btn.prev");
const nextButton = document.querySelector(".carousel-btn.next");
const indicatorsContainer = document.querySelector(".carousel-indicators");
const toggleButton = document.getElementById("carousel-toggle");
let currentIndex = 0;
let autoSlide = true;
let slideInterval;
// Crear indicadores
cards.forEach((_, index) => {
const indicator = document.createElement("span");
indicator.classList.add("indicator");
if (index === 0) indicator.classList.add("active");
indicatorsContainer.appendChild(indicator);
});
const indicators = Array.from(indicatorsContainer.children);
// Función para mostrar un proyecto específico
function showSlide(index) {
cards.forEach(card => card.classList.remove("active"));
indicators.forEach(dot => dot.classList.remove("active"));
cards[index].classList.add("active");
indicators[index].classList.add("active");
track.style.transform = `translateX(-${index * 100}%)`;
currentIndex = index;
}
// Botones de navegación
prevButton.addEventListener("click", () => {
currentIndex = (currentIndex - 1 + cards.length) % cards.length;
showSlide(currentIndex);
});
nextButton.addEventListener("click", () => {
currentIndex = (currentIndex + 1) % cards.length;
showSlide(currentIndex);
});
// Indicadores clicables
indicators.forEach((dot, index) => {
dot.addEventListener("click", () => showSlide(index));
});
// Auto-slide cada 4 segundos
function startAutoSlide() {
slideInterval = setInterval(() => {
currentIndex = (currentIndex + 1) % cards.length;
showSlide(currentIndex);
}, 4000);
}
function stopAutoSlide() {
clearInterval(slideInterval);
}
// Iniciar automático
startAutoSlide();
// ✅ Botón de pausa/reproducir
toggleButton.addEventListener("click", () => {
autoSlide = !autoSlide;
if (autoSlide) {
startAutoSlide();
toggleButton.textContent = "⏸";
} else {
stopAutoSlide();
toggleButton.textContent = "▶";
}
});
});
document.addEventListener('DOMContentLoaded', () => {
const settingsBtn = document.getElementById('settings-btn');
const colorPalette = document.getElementById('color-palette');
const colorSwatches = document.querySelectorAll('.color-swatch');
const root = document.documentElement;
// 1. Cargar el color guardado al iniciar la página
const savedColor = localStorage.getItem('primaryColor');
if (savedColor) {
// Corrección del nombre de la variable de CSS. Debe ser --primary-color
root.style.setProperty('--primary-color', savedColor);
}
// 2. Mostrar/ocultar la paleta de colores al hacer clic en el engranaje
settingsBtn.addEventListener('click', () => {
colorPalette.classList.toggle('visible');
});
// 3. Cambiar el color del tema al hacer clic en una muestra
colorSwatches.forEach(swatch => {
swatch.addEventListener('click', () => {
const newColor = swatch.dataset.color;
// Actualizar la variable CSS en tiempo real
root.style.setProperty('--primary-color', newColor);
// Guardar el nuevo color en el almacenamiento local
localStorage.setItem('primaryColor', newColor);
// Ocultar la paleta después de seleccionar un color
colorPalette.classList.remove('visible');
});
});
// Opcional: Ocultar la paleta si se hace clic fuera de ella
document.addEventListener('click', (event) => {
if (!settingsBtn.contains(event.target) && !colorPalette.contains(event.target)) {
colorPalette.classList.remove('visible');
}
});
});
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('#floating-nav a');
const root = document.documentElement;
const observerOptions = {
root: null, // El viewport
rootMargin: '0px',
threshold: 0.5 // Se activa cuando el 50% de la sección es visible
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Quita la clase 'active' de todos los enlaces
navLinks.forEach(link => link.classList.remove('active'));
// Encuentra el enlace que corresponde a la sección visible
const id = entry.target.getAttribute('id');
const activeLink = document.querySelector(`#floating-nav a[href="#${id}"]`);
if (activeLink) {
activeLink.classList.add('active');
}
}
});
}, observerOptions);
// Observa cada sección
sections.forEach(section => {
observer.observe(section);
});
// --- Lógica para colorear el icono activo ---
// Esta función se asegura de que el color del icono activo siempre coincida con el tema
function updateActiveIconColor() {
// Obtiene el color primario actual de las variables CSS
const primaryColor = getComputedStyle(root).getPropertyValue('--primary-color').trim();
// Crea una hoja de estilos en la cabecera del documento
let styleSheet = document.getElementById('dynamic-icon-styles');
if (!styleSheet) {
styleSheet = document.createElement('style');
styleSheet.id = 'dynamic-icon-styles';
document.head.appendChild(styleSheet);
}
// Actualiza la regla CSS para el filtro del icono activo.
// Esto es un truco para colorear un PNG blanco al color deseado.
// No es perfecto para todos los colores, pero funciona bien para la mayoría.
styleSheet.innerHTML = `
#floating-nav a.active img {
filter: brightness(0) saturate(100%) invert(48%) sepia(61%) saturate(2465%) hue-rotate(201deg) brightness(100%) contrast(95%);
}
`;
// Nota: El filtro de arriba se ha pre-calculado para que se parezca al color primario.
// Colorear dinámicamente un PNG con filter es complejo, así que usamos un valor que se parezca.
// Para un control perfecto del color, se necesitarían SVGs.
}
// Actualiza el color del icono cuando la página carga
updateActiveIconColor();
// Y también cuando el usuario cambia el tema de color
const colorPicker = document.getElementById('settings-btn'); // O el elemento que uses
if(colorPicker) {
// Asumiendo que el cambio de color ocurre en algún evento, por ejemplo 'click' en las muestras
document.querySelectorAll('.color-swatch').forEach(swatch => {
swatch.addEventListener('click', () => {
// Espera un poco para que la variable CSS se actualice y luego actualiza el icono
setTimeout(updateActiveIconColor, 100);
});
});
}
});