Alex Man Alex Man - 1 month ago 4
CSS Question

preventing main page scroll while we scroll the Overlay Navigation page

I have used a Full screen Overlay Navigation for displaying some of the detail. I have used the Full screen Overlay Navigation stuff which is been documented in w3schools - How TO - Full screen Overlay Navigation. Full Screen Navigation is working fine but the problem is with the scrolling. Lets say when we mouse scroll the mouse, the scrolling is happening for the main page. If we have a scroll bar for the Overlay Navigation Page and when it reaches the end of the scroll, then we can notice the main page started to scroll. I have made a JSFiddle to showcase the issue.

Working JSFiddle

function openNav() {
document.getElementById("mySidenav").style.width = "100%";
document.getElementById("main").style.marginLeft = "100%";
}

function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
}


Can anyone please tell me some solution for this

Answer

see the updated fiddle

function openNav() {
  document.getElementById("mySidenav").style.width = "100%";
  document.getElementById("main").style.marginLeft = "100%";
  document.body.style.overflow = "hidden";

}

function closeNav() {
  document.getElementById("mySidenav").style.width = "0";
  document.getElementById("main").style.marginLeft = "0";
   document.body.style.overflow = "auto";
}
Comments