Jump to content
Sign in to follow this  
BahnNguyen

Disable body scroll: How TO - Side Navigation

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>

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...