I just start learning Vue and trying to change styles for my header when the page scrolled up, down and when the scroll reached the top. In JS I have this :
var prevScrollpos = window.pageYOffset; const header = document.querySelector("header");
window.addEventListener("scroll", function () {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
header.classList.add("scrolled");
header.classList.remove("scrollDown");
}else {
header.classList.add("scrollDown");
header.classList.remove("scrolled");
}
if (currentScrollPos === 0) {
header.classList.remove("scrollDown");
header.classList.remove("scrolled");
}
prevScrollpos = currentScrollPos;
});
But I don't know how to make it in vue 3 Hope for your help Thanks in advance!