// Mobile Menu Toggle const hamburger = document.querySelector('.hamburger'); const navMenu = document.querySelector('.nav-menu'); if (hamburger) { hamburger.addEventListener('click', () => { hamburger.classList.toggle('active'); navMenu.classList.toggle('active'); }); } // Close mobile menu when clicking on a link document.querySelectorAll('.nav-menu a').forEach(link => { link.addEventListener('click', () => { hamburger.classList.remove('active'); navMenu.classList.remove('active'); }); }); // Hero Slider const slides = document.querySelectorAll('.slide'); const prevBtn = document.querySelector('.slider-btn.prev'); const nextBtn = document.querySelector('.slider-btn.next'); const dotsContainer = document.querySelector('.hero-dots'); let currentSlide = 0; let slideInterval; // Create dots if (slides.length > 0) { slides.forEach((_, index) => { const dot = document.createElement('button'); dot.classList.add('dot'); if (index === 0) dot.classList.add('active'); dot.addEventListener('click', () => goToSlide(index)); if (dotsContainer) dotsContainer.appendChild(dot); }); } function showSlide(index) { slides.forEach((slide, i) => { slide.classList.remove('active'); const dots = document.querySelectorAll('.dot'); if (dots[i]) dots[i].classList.remove('active'); }); if (slides[index]) { slides[index].classList.add('active'); const dots = document.querySelectorAll('.dot'); if (dots[index]) dots[index].classList.add('active'); } } function goToSlide(index) { currentSlide = index; showSlide(currentSlide); resetInterval(); } function nextSlide() { currentSlide = (currentSlide + 1) % slides.length; showSlide(currentSlide); } function prevSlide() { currentSlide = (currentSlide - 1 + slides.length) % slides.length; showSlide(currentSlide); } function startInterval() { slideInterval = setInterval(nextSlide, 5000); } function resetInterval() { clearInterval(slideInterval); startInterval(); } if (prevBtn && nextBtn) { prevBtn.addEventListener('click', () => { prevSlide(); resetInterval(); }); nextBtn.addEventListener('click', () => { nextSlide(); resetInterval(); }); } // Start slider if (slides.length > 0) { startInterval(); } // Smooth Scroll document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { const href = this.getAttribute('href'); if (href !== '#' && href.length > 1) { e.preventDefault(); const target = document.querySelector(href); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } }); }); // Scroll Animation const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; } }); }, observerOptions); // Observe elements document.querySelectorAll('.product-card, .feature-card, .industry-item').forEach(el => { el.style.opacity = '0'; el.style.transform = 'translateY(20px)'; el.style.transition = 'all 0.6s ease'; observer.observe(el); }); // Form Validation const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function(e) { e.preventDefault(); const inputs = form.querySelectorAll('input[required], textarea[required]'); let valid = true; inputs.forEach(input => { if (!input.value.trim()) { valid = false; input.style.borderColor = 'red'; } else { input.style.borderColor = '#00C292'; } }); if (valid) { // Here you would normally send the form data alert('¡Mensaje enviado correctamente! Nos pondremos en contacto contigo pronto.'); form.reset(); } else { alert('Por favor, complete todos los campos obligatorios.'); } }); }); // Sticky Header let lastScroll = 0; const header = document.querySelector('.header'); window.addEventListener('scroll', () => { const currentScroll = window.pageYOffset; if (currentScroll > 100) { header.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)'; } else { header.style.boxShadow = '0 2px 6px rgba(0,0,0,0.1)'; } lastScroll = currentScroll; }); // Active Navigation Link const sections = document.querySelectorAll('section[id]'); const navLinks = document.querySelectorAll('.nav-menu a'); window.addEventListener('scroll', () => { let current = ''; sections.forEach(section => { const sectionTop = section.offsetTop; const sectionHeight = section.clientHeight; if (pageYOffset >= sectionTop - 200) { current = section.getAttribute('id'); } }); navLinks.forEach(link => { link.classList.remove('active'); if (link.getAttribute('href') === `#${current}`) { link.classList.add('active'); } }); }); console.log('Westfalia Perú - Website loaded successfully');