/* ============================================= agrim.az — Shared JS (nav, footer, utils) ============================================= */ // ── STICKY NAV ──────────────────────────────── (function () { const nav = document.querySelector('.nav'); if (!nav) return; window.addEventListener('scroll', () => { nav.classList.toggle('scrolled', window.scrollY > 40); }); })(); // ── MOBILE MENU ─────────────────────────────── (function () { const burger = document.querySelector('.nav__burger'); const mobile = document.querySelector('.nav__mobile'); if (!burger || !mobile) return; burger.addEventListener('click', () => { mobile.classList.toggle('open'); const spans = burger.querySelectorAll('span'); const open = mobile.classList.contains('open'); spans[0].style.transform = open ? 'rotate(45deg) translate(5px,5px)' : ''; spans[1].style.opacity = open ? '0' : '1'; spans[2].style.transform = open ? 'rotate(-45deg) translate(5px,-5px)' : ''; }); document.addEventListener('click', e => { if (!nav.contains(e.target)) mobile.classList.remove('open'); }); })(); // ── SCROLL TO TOP ───────────────────────────── (function () { const btn = document.querySelector('.scroll-top'); if (!btn) return; window.addEventListener('scroll', () => { btn.classList.toggle('visible', window.scrollY > 400); }); btn.addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' })); })(); // ── ACTIVE NAV LINK ─────────────────────────── (function () { const path = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('.nav__link, .nav__mobile-link').forEach(a => { const href = a.getAttribute('href') || ''; if (href === path || (path === '' && href === 'index.html')) a.classList.add('active'); }); })(); // ── INTERSECTION OBSERVER (reveal on scroll) ── (function () { const els = document.querySelectorAll('[data-reveal]'); if (!els.length) return; const io = new IntersectionObserver(entries => { entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add('anim-up'); io.unobserve(e.target); } }); }, { threshold: 0.1, rootMargin: '0px 0px -40px 0px' }); els.forEach(el => io.observe(el)); })(); // ── COUNTER ANIMATION ───────────────────────── function animateCounter(el) { const target = parseInt(el.dataset.target, 10); const suffix = el.dataset.suffix || ''; const duration = 1600; const start = performance.now(); function step(now) { const t = Math.min((now - start) / duration, 1); const ease = 1 - Math.pow(1 - t, 4); el.textContent = Math.round(ease * target) + suffix; if (t < 1) requestAnimationFrame(step); } requestAnimationFrame(step); } (function () { const counters = document.querySelectorAll('[data-target]'); if (!counters.length) return; const io = new IntersectionObserver(entries => { entries.forEach(e => { if (e.isIntersecting) { animateCounter(e.target); io.unobserve(e.target); } }); }, { threshold: 0.5 }); counters.forEach(c => io.observe(c)); })();