seccion portfolio finish
This commit is contained in:
@@ -185,6 +185,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
if (yearEl) yearEl.textContent = new Date().getFullYear();
|
||||
|
||||
initServiciosAccordion();
|
||||
initNavbarAutoHide();
|
||||
|
||||
});
|
||||
|
||||
/* ============================================
|
||||
@@ -575,6 +577,97 @@ function initMarqueeHover() {
|
||||
});
|
||||
}
|
||||
|
||||
/*==========================================
|
||||
nav
|
||||
=============================================*/
|
||||
function initNavbarAutoHide() {
|
||||
console.log('🔵 initNavbarAutoHide: iniciando...');
|
||||
|
||||
// Reintentar hasta que el header exista (por si se carga async)
|
||||
let attempts = 0;
|
||||
const MAX_ATTEMPTS = 50; // 5 segundos
|
||||
|
||||
const tryInit = () => {
|
||||
const header = document.querySelector('.site-header');
|
||||
console.log('🔵 intento', attempts, '- header:', header);
|
||||
|
||||
if (!header) {
|
||||
attempts++;
|
||||
if (attempts < MAX_ATTEMPTS) {
|
||||
setTimeout(tryInit, 100);
|
||||
} else {
|
||||
console.error('❌ Navbar: no se encontró .site-header');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('✅ Navbar encontrado, registrando scroll listener...');
|
||||
|
||||
const hero = document.getElementById('hero');
|
||||
const UMBRAL_HERO = 100; // píxeles mínimos antes de activar el auto-hide
|
||||
let lastScrollY = window.scrollY;
|
||||
let ticking = false;
|
||||
|
||||
const updateHeader = () => {
|
||||
const currentScrollY = window.scrollY;
|
||||
const delta = currentScrollY - lastScrollY;
|
||||
|
||||
console.log('📜 scrollY:', currentScrollY, '| delta:', delta);
|
||||
|
||||
// 1. Si el menú fullscreen está abierto: siempre visible
|
||||
if (document.body.classList.contains('menu-open')) {
|
||||
header.classList.remove('is-hidden');
|
||||
lastScrollY = currentScrollY;
|
||||
ticking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Si estamos dentro del hero (primeros 100px): siempre visible
|
||||
if (currentScrollY <= UMBRAL_HERO) {
|
||||
header.classList.remove('is-hidden');
|
||||
lastScrollY = currentScrollY;
|
||||
ticking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Ignorar micro-movimientos
|
||||
if (Math.abs(delta) < 5) {
|
||||
ticking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Scroll hacia abajo → ocultar
|
||||
if (delta > 0) {
|
||||
header.classList.add('is-hidden');
|
||||
console.log(' → ocultando header');
|
||||
}
|
||||
// 5. Scroll hacia arriba → mostrar
|
||||
else {
|
||||
header.classList.remove('is-hidden');
|
||||
console.log(' → mostrando header');
|
||||
}
|
||||
|
||||
lastScrollY = currentScrollY;
|
||||
ticking = false;
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
if (!ticking) {
|
||||
window.requestAnimationFrame(updateHeader);
|
||||
ticking = true;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
// Resetear al redimensionar
|
||||
window.addEventListener('resize', () => {
|
||||
lastScrollY = window.scrollY;
|
||||
});
|
||||
|
||||
console.log('✅ Navbar auto-hide listo');
|
||||
};
|
||||
|
||||
tryInit();
|
||||
}
|
||||
|
||||
// Inicializar cuestionario al cargar la página
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
@@ -588,4 +681,5 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
initMetodologiaAnimation();
|
||||
initPlanesFocusEffect();
|
||||
initPortfolioCarousel();
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user