// js/ui.js // Shared UI enhancements: Glass Header on scroll & Back-to-Top button. document.addEventListener('DOMContentLoaded', () => { const header = document.querySelector('header.nav'); // Don't run if there's no header on the page if (!header) return; // 1. Create and inject Back-to-Top button const btt = document.createElement('div'); btt.className = 'back-to-top'; btt.setAttribute('aria-label', 'Scroll to top'); btt.innerHTML = ``; document.body.appendChild(btt); // 2. Click listener to scroll to top btt.addEventListener('click', () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }); // 3. Scroll listener to show/hide elements let isTicking = false; window.addEventListener('scroll', () => { if (!isTicking) { window.requestAnimationFrame(() => { const scrollY = window.scrollY; if (scrollY > 200) { btt.classList.add('visible'); } else { btt.classList.remove('visible'); } isTicking = false; }); isTicking = true; } }); });