I am new to jQuery and I am trying to create a "full page menu" on my own. However, I am struggling to hide the menu on the second click. I tried using .toggle() but I found out that it has been deprecated. Can someone assist me with this? Thank you so much and please excuse any mistakes in my English.
HTML
<div class="container">
<a id="bars" href="#">Open/Close Menu</a>
</div>
<nav id="nav" class="nav-default">
<ul>
<li>Home</li>
<li>Services</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
CSS
#bars {
position: fixed;
z-index: 2;
}
#nav {
position: absolute;
width: 100%;
height: 100%;
text-align: center;
}
#nav ul {
list-style: none;
}
.nav-default {
left: -100%;
top:0;
background: #ccc;
}
jQuery
$(document).ready(function() {
$("#bars").click(
function (){
$(".nav-default").animate({
left: "0"
}, 1000, function() {
// Animation complete.
});
});
});
Note: When I click the menu with this code, it only reveals!