I need to make a menu that when I click the button it appears and when I click it it disappears. Home
The problem I've been facing is that the event to make the menu disappear is the same as it appears, so it goes into a small loop.
How do I not activate the two events at the same time?
HTML and JavaScript below.
$("#btn-menu").click(function (){
$('.btn-menu').hide('slow');
$('.div-nav-menu').show('slow');
});
$('body').click(function (){
if(document.getElementById('1010').style.display == "block"){
$('.div-nav-menu').hide('slow');
$('.btn-menu').show('slow');
}
else{
return (false);
}
});
.div-nav-menu{
border-radius: 50%;
width: 500px;
height: 500px;
background-image: linear-gradient(65deg, #ff1414 15% , #002874 50%);
position: fixed;
z-index: 1000;
top: -250px;
right: -250px;
display: none;
}
.btn-menu{
width: 53px;
height: 53px;
background-image: linear-gradient(65deg, #ff1414, #002874);
color: white;
border-radius: 50%;
border: none;
margin-right: 260px;
margin-top: 76px;
}
<div class="div-menu">
<button class="btn-menu" id="btn-menu">menu</button>
<div class="div-nav-menu" id="1010">
<nav class="nav-menu">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>