Jump to content

Disable body scroll: How TO - Side Navigation


BahnNguyen
 Share

Recommended Posts

I followed the following tutorial and I was finally able to add a slide in menu on my WordPress site.


However, I noticed that the body scrolls when moving up and down on my mobile phone. Can someone explain to me how I can disable body scroll when the menu is opened?

 

Many thanks in advance!

Tutorial: https://www.w3schools.com/howto/howto_js_sidenav.asp

<script>
function openNav() {
  document.getElementById("mySidenav").style.width = "100%";
}

function closeNav() {
  document.getElementById("mySidenav").style.width = "0";
}
	
</script>

 

Link to comment
Share on other sites

I would recommend utilizing something like overflow-y in your code.

Set your body to the height of the screen, and set the overflow-y to hidden. That will eliminate the scrolling behaviour.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...