Created
November 5, 2019 09:24
-
-
Save rahuls360/f93004994eaf789b2f6dc0aadcd41b23 to your computer and use it in GitHub Desktop.
hide header when scrolling down
This file contains 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
<script> | |
/* When the user scrolls down, hide the navbar. When the user scrolls up, show the navbar */ | |
var prevScrollpos = window.pageYOffset; | |
window.onscroll = function() { | |
var currentScrollPos = window.pageYOffset; | |
if (prevScrollpos > currentScrollPos) { | |
document.querySelector("header").style.top = "0"; | |
} else { | |
document.querySelector("header").style.top = "-85px"; | |
} | |
prevScrollpos = currentScrollPos; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment