I had to setup my page with body > overflow-y:scroll
by default because It has a fixed header at the top, and when navigating fom one page with long content to one with less content the header moves rightwards. So this hack solved this issue temporarily...
Now, I'm trying to show an opacity overlay after clicking on a button, preventing the body from scrolling during the overlay is on.
What I tried was to use Jquery $(document.body).css('overflow-y','hidden');
during the click event to preventing the body from scrolling...It works, but the body content moves rightwards (scroll disappears)
How to solve this new problem?
$(".click_mebutton").click(function(){
$(".overlay").show();
$(document.body).css('overflow','hidden');
});
body {
height: 100%; overflow: scroll; /*overflow:hidden after jquery() execution*/
}
.body_container{
height: 100%;
}
.content{height:1000px;background:green}
.overlay{
display:none;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background-color: rgba(0, 0, 0, 0.8);
z-index:9999;
}
.top_fixed_header{
position: fixed
top: 0;
left: 0;
height: 40px;
background:red;
width: 100%;
min-width: 100px;
z-index: 999;
padding-top: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<html>
<body>
<div class=body_container>
<div class=top_fixed_header>header</div>
<div class=content>
<div class=click_mebutton>[click me button]</div>
</div>
</diV>
</diV>
</body>
</html>
<div class="overlay">Overlay</div>