const detectScrollDirection = () => {
let lastScrollTop = 0;
window.addEventListener("scroll", () => {
const header = document.querySelector(".site_nav");
const currentScrollTop =
document.body.scrollTop || document.documentElement.scrollTop;
if (currentScrollTop < lastScrollTop) { //<向下滚动,>向上滚动
header.classList.remove("scroll");
} else {
header.classList.add("scroll");
}
lastScrollTop = currentScrollTop;
});
};
detectScrollDirection();