I am facing a challenge with a large table that extends beyond the screen, requiring both horizontal and vertical scrolling. My goal is to create a sticky navbar that remains at the top when I scroll horizontally, but hides when I scroll vertically, only to reappear when I scroll back up to the top of the page.
Although I attempted a solution using CSS and JavaScript, the navbar also disappears when I scroll horizontally. It should only be hidden during vertical scrolling.
<style>
#sticky {
position: fixed;
top: 0;
width: 100%;
}
</style>
<script>
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("sticky").style.top = "0";
} else {
document.getElementById("sticky").style.top = "-70px";
}
prevScrollpos = currentScrollPos;
}
</script>