/** * TinyTorch Top Bar * Elegant navigation bar matching MLSysBook style */ document.addEventListener('DOMContentLoaded', function() { // Only inject if not already present if (document.getElementById('tinytorch-bar')) return; const barHTML = `
`; document.body.insertAdjacentHTML('afterbegin', barHTML); // Smart sticky: hide on scroll down, show on scroll up const bar = document.getElementById('tinytorch-bar'); let lastScrollY = window.scrollY; let ticking = false; function updateBar() { const currentScrollY = window.scrollY; if (currentScrollY < 50) { // Always show at top of page bar.classList.remove('hidden'); } else if (currentScrollY > lastScrollY) { // Scrolling down - hide bar.classList.add('hidden'); } else { // Scrolling up - show bar.classList.remove('hidden'); } lastScrollY = currentScrollY; ticking = false; } window.addEventListener('scroll', function() { if (!ticking) { requestAnimationFrame(updateBar); ticking = true; } }, { passive: true }); });