// Scroll animation observer function initScrollAnimations() { const fadeElements = document.querySelectorAll('.fade-up'); const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('visible'); } }); }, { threshold: 0.1 }); fadeElements.forEach(element => { observer.observe(element); }); } // Counter animation function animateCounters() { const counters = document.querySelectorAll('[data-count]'); const speed = 200; counters.forEach(counter => { const target = +counter.getAttribute('data-count'); const count = +counter.innerText.replace('+', ''); const increment = target / speed; if (count < target) { counter.innerText = Math.ceil(count + increment) + (counter.innerText.includes('+') ? '+' : ''); setTimeout(animateCounters, 1); } else { counter.innerText = target + (counter.innerText.includes('+') ? '+' : ''); } }); } document.addEventListener('DOMContentLoaded', function() { // Initialize Feather Icons initScrollAnimations(); animateCounters(); feather.replace(); // Video background fallback detection const videoBackgrounds = document.querySelectorAll('.video-background'); videoBackgrounds.forEach(background => { const video = background.querySelector('video'); if (!video || video.readyState < 3) { // Video not loaded background.classList.add('no-video'); } }); // Enhanced Lightbox Gallery Functionality for Portfolio const initPortfolioLightbox = () => { const lightbox = document.createElement('div'); lightbox.id = 'lightbox'; lightbox.innerHTML = ` `; document.body.appendChild(lightbox); // Initialize all project galleries document.querySelectorAll('.project-gallery').forEach(gallery => { const images = gallery.querySelectorAll('img'); images.forEach(img => { img.style.cursor = 'pointer'; img.addEventListener('click', (e) => { e.preventDefault(); openLightbox(gallery, img); }); }); }); const lightboxImg = lightbox.querySelector('.lightbox-img'); const lightboxCaption = lightbox.querySelector('.lightbox-caption'); const closeBtn = lightbox.querySelector('.close'); const prevBtn = lightbox.querySelector('.prev'); const nextBtn = lightbox.querySelector('.next'); let currentGallery = []; let currentIndex = 0; const openLightbox = (gallery, clickedImg) => { currentGallery = Array.from(gallery.querySelectorAll('img')); currentIndex = currentGallery.indexOf(clickedImg); updateLightbox(); lightbox.style.display = 'flex'; document.body.style.overflow = 'hidden'; }; const updateLightbox = () => { const currentImage = currentGallery[currentIndex]; lightboxImg.src = currentImage.src; lightboxImg.alt = currentImage.alt; // Set caption if available (from alt text or parent element) const caption = currentImage.alt || (currentImage.closest('div') && currentImage.closest('div').querySelector('h3'))?.textContent || ''; lightboxCaption.textContent = caption; }; const navigate = (direction) => { currentIndex = (currentIndex + direction + currentGallery.length) % currentGallery.length; updateLightbox(); }; prevBtn.addEventListener('click', () => navigate(-1)); nextBtn.addEventListener('click', () => navigate(1)); closeBtn.addEventListener('click', () => { lightbox.style.display = 'none'; document.body.style.overflow = 'auto'; }); lightbox.addEventListener('click', (e) => { if (e.target === lightbox) { lightbox.style.display = 'none'; document.body.style.overflow = 'auto'; } }); document.addEventListener('keydown', (e) => { if (lightbox.style.display === 'flex') { switch(e.key) { case 'Escape': lightbox.style.display = 'none'; document.body.style.overflow = 'auto'; break; case 'ArrowLeft': navigate(-1); break; case 'ArrowRight': navigate(1); break; } } }); }; initPortfolioLightbox(); // 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' }); } }); }); // Form submission handling const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function(e) { e.preventDefault(); // Here you would typically send the form data to a server alert('Gracias por tu mensaje. Nos pondremos en contacto contigo pronto.'); this.reset(); }); }); // Add any additional interactive elements here });