// Define the onScroll function let lastScrollY = 0; let scheduledAnimationFrame = false; function onScroll(evt) { lastScrollY = window.scrollY; if (scheduledAnimationFrame) return; scheduledAnimationFrame = true; requestAnimationFrame(readAndUpdatePage); } function readAndUpdatePage() { scheduledAnimationFrame = false; } // Attach the scroll event listener to the window window.addEventListener("scroll", onScroll); -->