Skip to content

Instantly share code, notes, and snippets.

@fathulfahmy
Last active July 9, 2024 16:29
Show Gist options
  • Save fathulfahmy/7f5c4f3dffa8224f52b968918932e3e7 to your computer and use it in GitHub Desktop.
Save fathulfahmy/7f5c4f3dffa8224f52b968918932e3e7 to your computer and use it in GitHub Desktop.
function hideNavbar() {
if (window.innerWidth >= 1024) {
console.log("desktop");
var prevScrollpos = window.scrollY;
window.onscroll = function () {
var currentScrollPos = window.scrollY;
if (prevScrollpos > currentScrollPos) {
navbar.style.top = "0";
} else {
navbar.style.top = "-" + navbar.offsetHeight + "px";
}
prevScrollpos = currentScrollPos;
};
} else {
// reset onscroll listener
window.onscroll = function () {};
}
}
hideNavbar();
window.onresize = hideNavbar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment