Spaces:
Running
Running
| // Carousel functionality | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize carousel | |
| const carousel = document.querySelector('.carousel-slide'); | |
| const carouselItems = document.querySelectorAll('.carousel-slide > div'); | |
| const prevBtn = document.querySelector('.carousel-prev'); | |
| const nextBtn = document.querySelector('.carousel-next'); | |
| const indicators = document.querySelectorAll('.carousel-indicator'); | |
| let currentIndex = 0; | |
| const itemCount = carouselItems.length; | |
| function updateCarousel() { | |
| const offset = -currentIndex * 100; | |
| carousel.style.transform = `translateX(${offset}%)`; | |
| // Update indicators | |
| indicators.forEach((indicator, index) => { | |
| if (index === currentIndex) { | |
| indicator.classList.add('bg-opacity-100'); | |
| indicator.classList.remove('bg-opacity-50'); | |
| } else { | |
| indicator.classList.add('bg-opacity-50'); | |
| indicator.classList.remove('bg-opacity-100'); | |
| } | |
| }); | |
| } | |
| function nextSlide() { | |
| currentIndex = (currentIndex + 1) % itemCount; | |
| updateCarousel(); | |
| } | |
| function prevSlide() { | |
| currentIndex = (currentIndex - 1 + itemCount) % itemCount; | |
| updateCarousel(); | |
| } | |
| // Event listeners | |
| nextBtn.addEventListener('click', nextSlide); | |
| prevBtn.addEventListener('click', prevSlide); | |
| // Indicator clicks | |
| indicators.forEach((indicator, index) => { | |
| indicator.addEventListener('click', () => { | |
| currentIndex = index; | |
| updateCarousel(); | |
| }); | |
| }); | |
| // Auto-advance carousel | |
| let carouselInterval = setInterval(nextSlide, 5000); | |
| // Pause on hover | |
| const carouselContainer = document.querySelector('.carousel-container'); | |
| carouselContainer.addEventListener('mouseenter', () => { | |
| clearInterval(carouselInterval); | |
| }); | |
| carouselContainer.addEventListener('mouseleave', () => { | |
| carouselInterval = setInterval(nextSlide, 5000); | |
| }); | |
| // Form submission | |
| const applicationForm = document.getElementById('applicationForm'); | |
| if (applicationForm) { | |
| applicationForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Here you would typically send the form data to a server | |
| alert('¡Solicitud enviada con éxito! Nos pondremos en contacto contigo pronto.'); | |
| this.reset(); | |
| }); | |
| } | |
| // Smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| const targetId = this.getAttribute('href'); | |
| if (targetId === '#') return; | |
| const targetElement = document.querySelector(targetId); | |
| if (targetElement) { | |
| targetElement.scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| } | |
| }); | |
| }); | |
| }); |