File size: 6,379 Bytes
662b84e 41b215d 1393517 41b215d f585cd5 41b215d 1393517 41b215d f585cd5 662b84e 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef bfa9ffb 9aeb2ef 662b84e f585cd5 3fd7e8c c9ab092 3fd7e8c f585cd5 bef76b6 f585cd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
// 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 = `
<div class="lightbox-content">
<span class="close">×</span>
<img src="" alt="" class="lightbox-img">
<div class="lightbox-caption"></div>
<div class="lightbox-nav">
<button class="prev">❮</button>
<button class="next">❯</button>
</div>
</div>
`;
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
}); |