mirror of
https://github.com/kogakure/website-11ty-kogakure.de.git
synced 2026-02-03 12:15:28 +00:00
25 lines
660 B
JavaScript
25 lines
660 B
JavaScript
export function scrollHandler() {
|
|
const body = document.body;
|
|
const scrollUp = 'scroll-up';
|
|
const scrollDown = 'scroll-down';
|
|
let lastScroll = 0;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
const currentScroll = window.pageYOffset;
|
|
|
|
if (currentScroll <= 0) {
|
|
body.classList.remove(scrollUp);
|
|
return;
|
|
}
|
|
|
|
if (currentScroll > lastScroll && !body.classList.contains(scrollDown)) {
|
|
body.classList.remove(scrollUp);
|
|
body.classList.add(scrollDown);
|
|
} else if (currentScroll < lastScroll && body.classList.contains(scrollDown)) {
|
|
body.classList.remove(scrollDown);
|
|
body.classList.add(scrollUp);
|
|
}
|
|
lastScroll = currentScroll;
|
|
});
|
|
}
|