How to create a sidebar menu with hamburger icon?

Asked

Viewed 1,142 times

2

1 answer

1

Hello, I created an app on xdk recently, in it I used the side bar, but the sandwich with an image :/

HTML button:

<button onclick="openNav()"><img class="btn-menu" src="img/threelines.png"></button>

HTML from side view

 <div id="mySidenav" class="slide-menu">
            <h1><b>Opções</b></h1>
            <a href="itens.html"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span><b>  Itens salvos por você!</b></a>
            <a href="pesquisa.html"><span class="glyphicon glyphicon-search" aria-hidden="true"></span><b>  Pesquisar!</b></a>
        </div>

CSS button (to keep it fixed on the right)

.btn-menu{
    font-size: 60px;
    color: #fff;
    width: 100px;
    height: 80px;
    left: 85%;
    position: fixed;
    z-index: 2;
    margin: 30px 10px 0 0;
    border-radius: 200px;
    border: none;
    background-color: #76b72a;
    opacity: 0.6;
    outline: none;
}
.btn-menu:hover{
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.4);
}

CSS from slide menu

.slide-menu{
height: 100%;
    width: 0;
    position: fixed;
    z-index: 5;
    top: 0;
    left: 0;
    background-color: #fff;
    overflow-x: hidden;
    padding-top: 60px; 
    transition: 0.3s;
    border-right: 2px solid;
    border-color: #000!important;

}
.slide-menu a{
    padding: 40px 5px 0px 30px;
    text-decoration: none;
    border-bottom: 2px solid;
    font-size: 50px;
    font-family: museosans;
    color: #606060;
    display: block;
    vertical-align: middle;
}
.slide-menu h1{
    padding: 20px 5px 0px 30px;
    font-size: 90px;
    font-family: caviar_dreams;
    color: #000;
    display: block;
}
.slide-menu a:hover, .offcanvas a:focus{
    color: #afafaf;
}

JS

function openNav() { //quando o botão é clicado
    document.getElementById("mySidenav").style.width = "60%";
    document.getElementById("main").style.opacity = "0.2";
}
function closeNav() { 
    document.getElementById("mySidenav").style.width = "0";
    document.getElementById("main").style.opacity = "1";

}
document.addEventListener("click", function(){ // quando o user toca na tela ele chama o closeNav e o syde menu volta a posição inicial.
    if ($("#mySidenav").innerWidth() == 0){
       // nothing
    }else{
         closeNav();
    }
});

I hope it helps you! just swap the boot img for the css animation you gave of example.

Browser other questions tagged

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