Overflow on off canvas menu?

Asked

Viewed 113 times

2

I’m making a menu off canvas, in fact it is always on the screen, and when I click the button, what moves is mine main, the problem is the overflow, when I open the menu it should not let me give scroll, but rather close the menu in case I click anything out of it. But it’s giving me overflow on the whole page. any suggestions? PS: I took inspiration from this site, credit to them, http://www.x-apps.com.br/ .

var menu = false;
$('#hamburguer').click(function() {
    if (menu === false) {
      mostraCanvas();
    } else {
      escondeCanvas();
    }
});

function escondeCanvas() {
    $("#main").css("padding-left", "0");
    $("html, body").css("overflow", "auto");

    menu = false;
}

function mostraCanvas() {
  $("#main").css("padding-left", "50vw");
  $("html, body").css("overflow", "hidden");
  menu = true;
}

$('.off-item').click(function() {
    escondeCanvas();
});
.off-canvas{
  padding-top: 10px;
  left: 0;
  background-color: #292929;
  height: 100vh;
  width: 50vw;
  position: fixed;
  text-align: left;
  overflow-y: hidden;
  overflow-x: hidden;
  z-index: -1;
}
#main{
  z-index: 9999;
  position: absolute;
  margin: 0 !important;
  transition: all .2s linear;
  -webkit-transition: padding .2s linear;
  -moz-transition: padding .2s linear;
  -o-transition: padding .2s linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
      <div class="topo" id="topo">
      <button id="hamburguer"><h1><span class="glyphicon glyphicon-menu-hamburger blue btn-nav"></span></h1><button>
    </div>
      <nav class="navbar" id="navbar">
         <ul>
            <a href="#banner" id="linkbanner">
               <li class="nav-item">
                  <h2>Inicio</h2>
               </li>
            </a>
            <a href="#sobremim">
               <li class="nav-item">
                  <h2>Sobre Mim</h2>
               </li>
            </a>
            <a href="#portfolio">
               <li class="nav-item">
                  <h2>Portfólio</h2>
               </li>
            </a>
            <a href="#habilidades">
               <li class="nav-item">
                  <h2>Habilidades</h2>
               </li>
            </a>
            <a href="#contato">
               <li class="nav-item">
                  <h2>Contato</h2>
               </li>
            </a>
         </ul>
      </nav>
    blablabla até o fim do main...
  </div>

  • 1

    You can explain better where to click to open and to close?

  • @Note that H1 inside the div "top" inside, that’s what I click, is that as I was just doing tests I didn’t use the button

  • 1

    @Tiagosilveira I can’t simulate the problem. What is Overflow having that shouldn’t? Here I cannot scroll the contents after opening the menu. It seems correct.

  • @leonfreire please log in to https://tiagosilveiraa.github.io/ log in to the mobile tools (or even by mobile), click on the menu icon and give the scroll, note the body’s behavior, it should not give scroll, it should close the menu. Thank you if you can help me :)

  • @Tiagosilveira I withdrew my answer because of the other problems. If I can solve everything, I post again.

  • Thank you @leonfreire , I will continue searching for the solution as well.

Show 1 more comment

1 answer

1

I came to see that you made some updates on the site and today I did some tests with your current version. Try the following changes to see if it works. (As I’m testing on a downloaded version of your site, I can’t see with 100% loyalty.)

In your script:

function escondeCanvas() {
    $("#main").css("padding-left", "0");
    $("body").css("overflow-x", "");
    $("nav").removeClass("open");
    menu = false;
}

function mostraCanvas() {
  $("#main").css("padding-left", "50vw");
  $("body").css("overflow-x", "hidden");
  $("nav").addClass("open");
  menu = true;
}

In your CSS:

nav.open {
    z-index: 1;
}
nav.open + #main {
    height: 100vh;
    overflow-y: hidden;
}
  • Poxa, amigo, really solved, but now the links do not click, any suggestions? Or better, the links are not clickable...

  • another thing is when I return the main to the place the scroll remains disabled :/

  • @See if these changes help you.

  • @Calm tiagosilveira that I noticed is still in the cut. But I had solved and just forgot to add there. I will see again! xD

  • @Now yes. Look here!

  • worked, but when I activate the menu it automatically gives the scroll to the top of the page, it must be because of Overflow-y, some hack for such?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.