Skip to content

Instantly share code, notes, and snippets.

@TechWithTy
Created August 12, 2019 23:24
Show Gist options
  • Save TechWithTy/0c2a493a6a3ea65714077183e04a7be8 to your computer and use it in GitHub Desktop.
Save TechWithTy/0c2a493a6a3ea65714077183e04a7be8 to your computer and use it in GitHub Desktop.
// OnScroll Hide (Mobile)
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos || document.body.scrollTop <= 10) {
document.getElementById('navbar').style.top = '0';
// document.getElementById('navbar').style.opacity = '1';
} else {
document.getElementById('navbar').style.top = '-500px';
}
if (document.body.scrollTop <= 10) {
document.getElementById('navbar').style.opacity = '1';
}
prevScrollpos = currentScrollPos;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment