-2
I have the following menu and would like that when a submenu is opened, any other submenu previously opened would automatically close to not "pollute" the sidebar, keeping only one submenu open at a time. Does anyone have any idea what I can implement to solve this ?
<nav class="sidebar">
<div class="text">Side Menu</div>
<ul>
<li><a href="#">Página inicial</a></li>
<li><a href="#" class="tay-btn">Série de Taylor<span class="fas fa-caret-down first"></span></a>
<ul class="tay-show">
<li><a href="#">Aproximação e Erro</a></li>
</ul>
</li>
<li>
<a href="#"class="rai-btn">Raízes <span class="fas fa-caret-down second"></span></a>
<ul class="rai-show">
<li><a href="#">Bissecção</a></li>
<li><a href="#">Falsa posição</a></li>
<li><a href="#">Newton-Raphson</a></li>
<li><a href="#">Secante</a></li>
</ul>
</li>
<li>
<a href="#" class="sis-btn">Sistemas lineares<span class="fas fa-caret-down third"></span></a>
<ul class="sis-show">
<li><a href="#">Sistemas triangulares</a></li>
<li><a href="#">Método de Gauss</a></li>
<li><a href="#">Decomposição LU</a></li>
<li><a href="#">Jacobi</a></li>
<li><a href="#">Gauss-Seidel</a></li>
</ul>
</li>
<li>
<a href="#" class="mmq-btn">MMQ<span class="fas fa-caret-down fourth"></span></a>
<ul class="mmq-show">
<li><a href="#">Regressão linear</a></li>
<li><a href="#">Regressão polinomial</a></li>
<li><a href="#">Caso Geral</a></li>
</ul>
</li>
<li>
<a href="#" class="inter-btn">Interpolação<span class="fas fa-caret-down fifth"></span></a>
<ul class="inter-show">
<li><a href="#">Lagrange</a></li>
<li><a href="#">Newton</a></li>
</ul>
</li>
<li>
<a href="#" class="integ-btn">Integração<span class="fas fa-caret-down sixth"></span></a>
<ul class="integ-show">
<li><a href="#">Regra do trapézio</a></li>
<li><a href="#">Simpson 1/3</a></li>
<li><a href="#">Simpson 3/8</a></li>
</ul>
</li>
<li>
<a href="#" class="edo-btn">EDOs<span class="fas fa-caret-down seventh"></span></a>
<ul class="edo-show">
<li><a href="#">Método de Euler</a></li>
<li><a href="#">Método de Geun</a></li>
<li><a href="#">Método do Ponto Médio</a></li>
<li><a href="#">Métodos de Runge-Kutta</a></li>
</ul>
</li>
</ul>
</nav>
and the jquery script is like this:
<script>
$('.tay-btn').click(function(){
$('nav ul .tay-show').toggleClass("show");
$('nav ul .first').toggleClass("rotate");
});
$('.rai-btn').click(function(){
$('nav ul .rai-show').toggleClass("show1");
$('nav ul .second').toggleClass("rotate");
});
$('.sis-btn').click(function(){
$('nav ul .sis-show').toggleClass("show2");
$('nav ul .third').toggleClass("rotate");
});
$('.mmq-btn').click(function(){
$('nav ul .mmq-show').toggleClass("show3");
$('nav ul .fourth').toggleClass("rotate");
});
$('.inter-btn').click(function(){
$('nav ul .inter-show').toggleClass("show4");
$('nav ul .fifth').toggleClass("rotate");
});
$('.integ-btn').click(function(){
$('nav ul .integ-show').toggleClass("show5");
$('nav ul .sixth').toggleClass("rotate");
});
$('.edo-btn').click(function(){
$('nav ul .edo-show').toggleClass("show6");
$('nav ul .seventh').toggleClass("rotate");
});
</script>
And the css:
*
{
margin: 0;
padding: 0;
user-select: none;
box-sizing: border-box;
color: white;
font-family: 'Poppins', sans-serif;
}
.sidebar
{
position: fixed;
width: 250px;
height: 100%;
height: 100%;
left: 0;
background: #1b1b1b;
}
.sidebar .text
{
color: white;
font-size: 25px;
font-weight: 65px;
text-align: center;
background: #1e1e1e;
letter-spacing: 1px;
}
nav ul
{
background: #1b1b1b;
height: 100%;
width: 100%;
list-style: none;
}
nav ul li
{
line-height: 60px;
border-bottom: 1px solid rgba(255,255,255,0.1);
}
nav ul li a
{
position: relative;
color: white;
text-decoration: none;
font-size: 18px;
padding-left: 40px;
font-weight: 500;
display: block;
width: 100%;
border-left: 3px solid transparent;
}
nav ul li a:hover
{
color: cyan;
background: #1e1e1e;
border-left-color: cyan;
}
nav ul ul
{
position: static;
display: none;
}
nav ul ul li
{
position: static;
line-height: 42px;
border-bottom: none;
}
nav ul ul li a
{
font-size: 14px;
color: #e6e6e6;
padding-left: 45px;
}
nav ul li a span
{
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
font-size: 22px;
transition: transform 0.4s;
}
nav ul li a span.rotate
{
transform: translateY(-50%) rotate(-180deg);
}
nav ul .tay-show.show
{
display:block;
}
nav ul .rai-show.show1
{
display:block;
}
nav ul .sis-show.show2
{
display:block;
}
nav ul .mmq-show.show3
{
display:block;
}
nav ul .inter-show.show4
{
display:block;
}
nav ul .integ-show.show5
{
display:block;
}
nav ul .edo-show.show6
{
display:block;
}
Friend, edit your question. I can not understand exactly your doubt. Probably your post will be closed if it continues like this.
– Wan
Okay. I hope that’s clear
– Igor Sérgio
Missing the CSS also.
– Sam
the <Nav> ended up staying before the ```. Now it’s appearing. I added the css
– Igor Sérgio