// Intersection Observer for scroll animations document.addEventListener('DOMContentLoaded', function() { 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.classList.add('animate-fade-in'); } }); }, observerOptions); // Observe elements that should animate on scroll const elementsToObserve = document.querySelectorAll('section'); elementsToObserve.forEach(el => { observer.observe(el); }); // Stat counter animation const animateCounters = () => { const counters = document.querySelectorAll('[data-count]'); counters.forEach(counter => { const target = parseInt(counter.getAttribute('data-count')); const duration = 2000; const step = target / (duration / 16); let current = 0; const timer = setInterval(() => { current += step; if (current >= target) { counter.textContent = target; clearInterval(timer); } else { counter.textContent = Math.floor(current); } }, 16); }); }; // Trigger counter animation when stats section is visible const statsSection = document.querySelector('.grid'); if (statsSection) { const statsObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { animateCounters(); statsObserver.unobserve(entry.target); } }); }, { threshold: 0.5 }); statsObserver.observe(statsSection); } }); // Mobile menu toggle function toggleMobileMenu() { const mobileMenu = document.querySelector('.mobile-menu'); const overlay = document.querySelector('.overlay'); const hamburger = document.querySelector('.hamburger'); if (mobileMenu && overlay && hamburger) { mobileMenu.classList.toggle('active'); overlay.classList.toggle('active'); hamburger.classList.toggle('active'); } } // Close mobile menu when clicking overlay function closeMobileMenu() { const mobileMenu = document.querySelector('.mobile-menu'); const overlay = document.querySelector('.overlay'); const hamburger = document.querySelector('.hamburger'); if (mobileMenu && overlay && hamburger) { mobileMenu.classList.remove('active'); overlay.classList.remove('active'); hamburger.classList.remove('active'); } } // Work filtering functionality (for work page) let selectedCategory = 'all'; function showCategory(category) { selectedCategory = category; // Update tab buttons const tabButtons = document.querySelectorAll('.tab-button'); tabButtons.forEach(btn => { if (btn.getAttribute('onclick').includes(category)) { btn.classList.add('bg-gray-900', 'text-white'); btn.classList.remove('bg-gray-200', 'text-gray-700'); } else { btn.classList.add('bg-gray-200', 'text-gray-700'); btn.classList.remove('bg-gray-900', 'text-white'); } }); // Show/hide projects with animation const tabContents = document.querySelectorAll('.tab-content'); tabContents.forEach(content => { content.classList.remove('active'); }); const activeContent = document.querySelector(`.tab-content[data-category="${category}"]`); if (activeContent) { setTimeout(() => { activeContent.classList.add('active'); }, 100); } } // Project modal functionality (for work page) function openProject(title) { const modal = document.createElement('div'); modal.className = 'fixed inset-0 z-50 flex items-center justify-center p-4 modal-backdrop'; modal.style.backgroundColor = 'rgba(0, 0, 0, 0.8)'; modal.innerHTML = `
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.