Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.addEventListener ('DOMContentLoaded', ()=> {
- const body = document.body,
- scrollUp = "scroll-up",
- scrollDown = "scroll-down";
- let lastScroll = 0;
- //check for scrol action
- window.addEventListener ('scroll', ()=> {
- //hide and reveal header
- const currentScroll = window.pageYOffset;
- if (currentScroll <= 200) {
- body.classList.remove(scrollUp);
- return;
- }
- if (currentScroll > lastScroll && !body.classList.contains(scrollDown)) {
- // down
- body.classList.remove(scrollUp);
- body.classList.add(scrollDown);
- } else if (
- currentScroll < lastScroll &&
- body.classList.contains(scrollDown)
- ) {
- // up
- body.classList.remove(scrollDown);
- body.classList.add(scrollUp);
- }
- lastScroll = currentScroll;
- })
- // end scroll action
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement