Everything is working fine but I want to throttle this scroll event using requestAnimationFrame
const header = document.querySelector("header#site-header");
let lastScroll = Math.round(window.scrollY);
function onScroll() {
const currentScroll = Math.round(window.scrollY);
if (currentScroll <= 50) return header.classList.remove("scrolled");
if (currentScroll > lastScroll + 1) header.classList.add("scrolled");
else if (currentScroll < lastScroll - 1) header.classList.remove("scrolled");
lastScroll = currentScroll;
// console.log("scrolled");
}
window.addEventListener("scroll", onScroll);