Implementar navbar sticky con Bootstrap 5 y animaciones - Issue #7

Implementación completa de navbar sticky con menú hamburguesa responsive según especificaciones del template del cliente:

**Archivos Modificados:**
- header.php: Reescritura completa con navbar Bootstrap 5, sticky positioning, y responsive hamburger menu
- functions.php: Agregado require para nav-walker.php
- inc/enqueue-scripts.php: Agregado enqueue de custom-style.css y main.js

**Archivos Creados:**
- assets/css/custom-style.css: Estilos navbar con animaciones (gradient underline, dropdown slideDown, etc.)
- assets/js/main.js: JavaScript para scroll effect, active menu highlight, y mobile auto-close
- inc/nav-walker.php: Bootstrap 5 Nav Walker para dropdowns WordPress

**Características:**
 Navbar sticky con transición de sombra al hacer scroll
 Gradient underline animation en hover de nav-links
 Dropdown menus con animación slideDown
 Menú hamburguesa responsive (< 991px)
 Auto-close mobile menu al hacer click en enlaces
 Active menu item highlighting
 Smooth scroll para anchor links
 Skip link para accesibilidad
 Compatible con WordPress menu system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-04 16:27:54 -06:00
parent 928e543215
commit 5440f23512
6 changed files with 712 additions and 93 deletions

View File

@@ -0,0 +1,276 @@
/**
* Custom Styles - APUS Theme
*
* Estilos personalizados según el template del cliente.
* Incluye: Navbar sticky, animaciones, y componentes específicos.
*
* @package Apus_Theme
* @since 1.0.0
*/
/* ============================================
NAVBAR STICKY CON ANIMACIONES
============================================ */
.navbar {
position: sticky;
top: 0;
z-index: 1030;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.navbar.scrolled {
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
background-color: #fff !important;
}
/* Gradient underline animation en hover */
.nav-link {
position: relative;
transition: all 0.3s ease;
padding: 0.5rem 1rem !important;
font-weight: 500;
}
.nav-link::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%) scaleX(0);
width: 80%;
height: 2px;
background: linear-gradient(90deg, #0d6efd, #0dcaf0);
transition: transform 0.3s ease;
}
.nav-link:hover {
color: #0d6efd !important;
background-color: rgba(13, 110, 253, 0.05);
border-radius: 4px;
transform: translateY(-2px);
}
.nav-link:hover::after {
transform: translateX(-50%) scaleX(1);
}
/* Active nav link */
.nav-link.active,
.nav-item.current-menu-item > .nav-link {
color: #0d6efd !important;
font-weight: 600;
}
.nav-link.active::after,
.nav-item.current-menu-item > .nav-link::after {
transform: translateX(-50%) scaleX(1);
}
/* Dropdown animations */
.dropdown-menu {
border: none;
box-shadow: 0 8px 24px rgba(0,0,0,0.12);
border-radius: 8px;
animation: slideDown 0.3s ease;
margin-top: 0.5rem;
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.dropdown-item {
padding: 0.75rem 1.5rem;
transition: all 0.2s ease;
font-weight: 400;
}
.dropdown-item:hover,
.dropdown-item:focus {
background: linear-gradient(90deg, rgba(13, 110, 253, 0.1), rgba(13, 202, 240, 0.1));
color: #0d6efd;
transform: translateX(5px);
}
.dropdown-item.active {
background-color: rgba(13, 110, 253, 0.1);
color: #0d6efd;
}
/* Navbar Brand */
.navbar-brand {
font-weight: 700;
font-size: 1.5rem;
color: #1a1a1a;
transition: all 0.3s ease;
}
.navbar-brand:hover {
color: #0d6efd;
transform: scale(1.05);
}
/* Navbar Toggler (Hamburger) */
.navbar-toggler {
border: 2px solid rgba(0, 0, 0, 0.1);
padding: 0.5rem 0.75rem;
transition: all 0.3s ease;
}
.navbar-toggler:hover {
border-color: #0d6efd;
background-color: rgba(13, 110, 253, 0.05);
}
.navbar-toggler:focus {
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
/* Mobile Menu Styles */
@media (max-width: 991px) {
.navbar-collapse {
margin-top: 1rem;
padding: 1rem 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.nav-link {
padding: 0.75rem 1rem !important;
}
.nav-link::after {
display: none;
}
.dropdown-menu {
border: none;
box-shadow: none;
animation: none;
background-color: rgba(0, 0, 0, 0.02);
margin-left: 1rem;
padding: 0.5rem 0;
}
.dropdown-item {
padding: 0.5rem 1rem;
}
.dropdown-item:hover {
transform: none;
}
}
/* ============================================
SKIP LINK (Accesibilidad)
============================================ */
.skip-link.screen-reader-text {
position: absolute;
left: -9999px;
top: 2.5em;
z-index: 100000;
padding: 1em 1.5em;
background-color: #0d6efd;
color: #fff;
text-decoration: none;
font-size: 0.875rem;
font-weight: 600;
border-radius: 4px;
}
.skip-link.screen-reader-text:focus {
left: 6px;
outline: 3px solid rgba(13, 110, 253, 0.5);
outline-offset: 2px;
}
/* ============================================
SITE CONTENT SPACING
============================================ */
.site-content {
margin-top: 2rem;
margin-bottom: 2rem;
}
@media (max-width: 767px) {
.site-content {
margin-top: 1rem;
margin-bottom: 1rem;
}
}
/* ============================================
WORDPRESS SPECIFIC CLASSES
============================================ */
/* WordPress Menu Classes */
.menu-item {
position: relative;
}
.menu-item-has-children > .nav-link {
padding-right: 1.5rem !important;
}
/* Submenu Indicator (si se usan íconos) */
.menu-item-has-children > .nav-link::before {
content: '';
position: absolute;
right: 0.5rem;
top: 50%;
transform: translateY(-50%);
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 5px solid currentColor;
opacity: 0.6;
}
/* ============================================
UTILITY CLASSES
============================================ */
/* Screen Reader Only Text */
.screen-reader-text {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
word-wrap: normal !important;
}
.screen-reader-text:focus {
background-color: #f1f1f1;
border-radius: 3px;
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
clip: auto !important;
clip-path: none;
color: #21759b;
display: block;
font-size: 0.875rem;
font-weight: 700;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000;
}

View File

@@ -0,0 +1,144 @@
/**
* Main JavaScript - APUS Theme
*
* Funcionalidades principales del tema según template del cliente.
* Incluye: Navbar sticky scroll effect y animaciones.
*
* @package Apus_Theme
* @since 1.0.0
*/
(function() {
'use strict';
/**
* Navbar Scroll Effect
* Añade clase 'scrolled' al navbar cuando se hace scroll > 50px
*/
function initNavbarScrollEffect() {
const navbar = document.querySelector('.navbar');
if (!navbar) {
return;
}
// Optimización con throttle para mejor performance
let ticking = false;
function updateNavbar() {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
ticking = false;
}
window.addEventListener('scroll', function() {
if (!ticking) {
window.requestAnimationFrame(updateNavbar);
ticking = true;
}
});
// Ejecutar una vez al cargar por si la página ya tiene scroll
updateNavbar();
}
/**
* Highlight Active Menu Item
* Marca el item del menú correspondiente a la página actual
*/
function highlightActiveMenuItem() {
const currentUrl = window.location.href;
const navLinks = document.querySelectorAll('.navbar-nav .nav-link');
navLinks.forEach(function(link) {
// Remover active de todos
link.classList.remove('active');
// Agregar active si coincide URL
if (link.href === currentUrl) {
link.classList.add('active');
}
});
}
/**
* Mobile Menu Close on Link Click
* Cierra el menú móvil automáticamente al hacer click en un enlace
*/
function initMobileMenuAutoClose() {
const navbarToggler = document.querySelector('.navbar-toggler');
const navbarCollapse = document.querySelector('.navbar-collapse');
const navLinks = document.querySelectorAll('.navbar-nav .nav-link');
if (!navbarToggler || !navbarCollapse) {
return;
}
navLinks.forEach(function(link) {
link.addEventListener('click', function() {
// Solo en móvil (cuando el toggler es visible)
if (window.getComputedStyle(navbarToggler).display !== 'none') {
const bsCollapse = bootstrap.Collapse.getInstance(navbarCollapse);
if (bsCollapse) {
bsCollapse.hide();
}
}
});
});
}
/**
* Smooth Scroll for Anchor Links
* Scroll suave para enlaces ancla (#)
*/
function initSmoothScroll() {
const anchorLinks = document.querySelectorAll('a[href^="#"]');
anchorLinks.forEach(function(link) {
link.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
// Ignorar enlaces # vacíos o solo #
if (targetId === '#' || targetId === '') {
return;
}
const targetElement = document.querySelector(targetId);
if (targetElement) {
e.preventDefault();
// Offset por el navbar sticky
const navbarHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - navbarHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
}
/**
* Initialize all functions when DOM is ready
*/
function init() {
initNavbarScrollEffect();
highlightActiveMenuItem();
initMobileMenuAutoClose();
initSmoothScroll();
}
// DOM Ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();