feat: button disappear when scrolling down #16
This commit is contained in:
parent
8cabd64acb
commit
efeeba4743
1 changed files with 20 additions and 0 deletions
|
@ -116,3 +116,23 @@ function toggleAnimation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastScrollTop = 0; // Last position of the scroll
|
||||||
|
|
||||||
|
window.addEventListener("scroll", function() {
|
||||||
|
let currentPosition = window.pageYOffset || document.documentElement.scrollTop;
|
||||||
|
const toggleButton = document.querySelectorAll('.toggleButton');
|
||||||
|
|
||||||
|
if (currentPosition > lastScrollTop) {
|
||||||
|
// Scroll down
|
||||||
|
toggleButton.forEach(button => {
|
||||||
|
button.style.display = "none";
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Scroll up
|
||||||
|
toggleButton.forEach(button => {
|
||||||
|
button.style.display = "block";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
lastScrollTop = currentPosition <= 0 ? 0 : currentPosition; // For Mobile or negative scrolling
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue