Last active
June 24, 2021 08:52
-
-
Save peterkarn/d1cb38b7fa4de51bc196b084bdaabe1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
header = document.querySelector('.header'); | |
let lastScrollTop = 0; | |
window.addEventListener('scroll', () => { | |
let scrollDistance = window.scrollY; | |
if (scrollDistance > lastScrollTop) { | |
header.classList.remove('scrollable'); | |
header.style.opacity = ""; | |
header.style.transform = 'translateY(-10px)'; | |
} else { | |
// header.style.opacity = 1; | |
header.style.transform = 'translateY(0)'; | |
header.classList.add('scrollable'); | |
} | |
lastScrollTop = scrollDistance; | |
if (lastScrollTop === 0) { | |
header.classList.remove('scrollable'); | |
header.style.opacity = ""; | |
header.style.transform = 'translateY(0)'; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment