Skip to content

Instantly share code, notes, and snippets.

@rahuls360
Created November 5, 2019 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahuls360/f93004994eaf789b2f6dc0aadcd41b23 to your computer and use it in GitHub Desktop.
Save rahuls360/f93004994eaf789b2f6dc0aadcd41b23 to your computer and use it in GitHub Desktop.
hide header when scrolling down
<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