My JavaScript for hiding navigation menu button on scrolling page down and showing on scrolling up does not work with css hack to prevent page in background scrolling when menu is displayed on layer. (here is css method demo page: http://www.luxiyalu.com/playground/overlay/ )
I do suck in JavaScript. I tried to modify script - make it work using element.scrollWidth and element.offsetWidth relation to detect scrolling but can't nail it.
<div class="overlay">
<div class="overlay-content"></div>
</div>
<div class="background-content">
lengthy content here
</div>
html, body {
height: 100%;
}
.overlay{
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: rgba(0, 0, 0, 0.8);
.overlay-content {
height: 100%;
overflow: scroll;
}
}
.background-content{
height: 100%;
overflow: auto;
}
<script type="text/javascript">
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("mobilemenu").style.top = "0";
} else {
document.getElementById("mobilemenu").style.top = "-70px";
}
prevScrollpos = currentScrollPos;
}
</script>-->
Menu button should be hidden when scrolling down and should reappear when scrolling up WHILE page is styled as presented above.