How to create a sidebar menu with hamburger icon?

2

I'm starting to use Intel XDK now and I have a question regarding the development of menus, I would like to create a side menu with the burger icon and after opening the menu, it becomes a X to close.

Here are some examples:

I would like to know if it is possible and how I should proceed.

    
asked by anonymous 10.04.2015 / 06:43

1 answer

1

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

Button HTML:

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

Side view HTML

 <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>

Button CSS (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 of the 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();
    }
});

Hope you can help! just change the img of the button by the css animation that gave the example.

    
31.03.2017 / 16:48