Cabeçalho que muda de estilo ao rolar a página, usando Intersection Observer.
// Adiciona classe ao header quando sai do topo
const sentinel = document.createElement('div');
sentinel.style.cssText = 'position:absolute;top:0;height:1px;width:100%;pointer-events:none';
document.body.prepend(sentinel);
const header = document.querySelector('header');
new IntersectionObserver(([entry]) => {
header.classList.toggle('header--sticky', !entry.isIntersecting);
}).observe(sentinel);
// CSS:
// .header--sticky {
// position: fixed;
// top: 0;
// box-shadow: 0 2px 8px rgba(0,0,0,0.1);
// background: rgba(255,255,255,0.95);
// backdrop-filter: blur(8px);
// }