/* Revantis — main.js */ document.addEventListener('DOMContentLoaded', () => { /* ── Navbar scroll effect ── */ const navbar = document.querySelector('.navbar'); const handleScroll = () => { if (window.scrollY > 40) { navbar.classList.add('scrolled'); navbar.classList.remove('transparent'); } else { navbar.classList.remove('scrolled'); navbar.classList.add('transparent'); } }; window.addEventListener('scroll', handleScroll, { passive: true }); handleScroll(); /* ── Mobile menu ── */ const hamburger = document.querySelector('.navbar__hamburger'); const navLinks = document.querySelector('.navbar__links'); if (hamburger && navLinks) { hamburger.addEventListener('click', () => { navLinks.classList.toggle('open'); const bars = hamburger.querySelectorAll('span'); const isOpen = navLinks.classList.contains('open'); bars[0].style.transform = isOpen ? 'translateY(7px) rotate(45deg)' : ''; bars[1].style.opacity = isOpen ? '0' : '1'; bars[2].style.transform = isOpen ? 'translateY(-7px) rotate(-45deg)' : ''; }); // Close on link click navLinks.querySelectorAll('a').forEach(a => { a.addEventListener('click', () => { navLinks.classList.remove('open'); hamburger.querySelectorAll('span').forEach(s => { s.style.transform = ''; s.style.opacity = '1'; }); }); }); } /* ── Active nav link ── */ const currentPage = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('.navbar__links a').forEach(a => { const href = a.getAttribute('href'); if (href === currentPage || (currentPage === '' && href === 'index.html')) { a.classList.add('active'); } }); /* ── Scroll reveal ── */ const reveals = document.querySelectorAll('.reveal'); if ('IntersectionObserver' in window) { const observer = new IntersectionObserver((entries) => { entries.forEach((entry, i) => { if (entry.isIntersecting) { setTimeout(() => entry.target.classList.add('visible'), i * 80); observer.unobserve(entry.target); } }); }, { threshold: 0.12 }); reveals.forEach(el => observer.observe(el)); } else { reveals.forEach(el => el.classList.add('visible')); } /* ── Counter animation (stats) ── */ const counters = document.querySelectorAll('[data-count]'); if (counters.length) { const countObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { animateCount(entry.target); countObserver.unobserve(entry.target); } }); }, { threshold: 0.5 }); counters.forEach(c => countObserver.observe(c)); } function animateCount(el) { const target = parseFloat(el.getAttribute('data-count')); const suffix = el.getAttribute('data-suffix') || ''; const prefix = el.getAttribute('data-prefix') || ''; const duration = 1600; const steps = 60; const step = target / steps; let current = 0; let frame = 0; const timer = setInterval(() => { frame++; current = Math.min(step * frame, target); const display = Number.isInteger(target) ? Math.round(current) : current.toFixed(1); el.textContent = prefix + display + suffix; if (frame >= steps) clearInterval(timer); }, duration / steps); } /* ── Contact form ── */ const form = document.getElementById('contactForm'); if (form) { form.addEventListener('submit', (e) => { e.preventDefault(); const btn = form.querySelector('[type="submit"]'); const original = btn.textContent; btn.textContent = 'Message Sent ✓'; btn.disabled = true; btn.style.background = '#2d7d46'; btn.style.borderColor = '#2d7d46'; btn.style.color = '#fff'; setTimeout(() => { btn.textContent = original; btn.disabled = false; btn.style = ''; form.reset(); }, 3000); }); } /* ── Blog filter (blog page) ── */ const filterBtns = document.querySelectorAll('.filter-btn'); const blogCards = document.querySelectorAll('[data-category]'); filterBtns.forEach(btn => { btn.addEventListener('click', () => { filterBtns.forEach(b => b.classList.remove('active')); btn.classList.add('active'); const filter = btn.dataset.filter; blogCards.forEach(card => { if (filter === 'all' || card.dataset.category === filter) { card.style.display = ''; } else { card.style.display = 'none'; } }); }); }); });