I'm trying to create a responsive menu with menus and submenus using JQuery. However, as a newbie to JQuery, I'm struggling to hide a previous submenu when displaying another one.
Below is the HTML code:
<nav class="products">
<ul>
<li class="brown link-menu"><a href="#">wine essentials</a>
<div class="sub-menu">
<div class="content-sub-menu">
<ul class="sub-menu-list">
<li class="link-subcat"><a href="#" class="menu-subcat-link">standard</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">super premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">ultra premium</a></li>
</ul>
</div>
</div>
</li>
<li class="pink link-menu"><a href="#">wine selective & prestige</a>
<div class="sub-menu">
<div class="content-sub-menu">
<ul class="sub-menu-list">
<li class="link-subcat"><a href="#" class="menu-subcat-link">standard</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">super premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">ultra premium</a></li>
</ul>
</div>
</div>
</li>
<li class="green link-menu"><a href="#">master distillers</a>
<div class="sub-menu">
<div class="content-sub-menu">
<ul class="sub-menu-list">
<li class="link-subcat"><a href="#" class="menu-subcat-link">standard</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">super premium</a></li>
<li class="link-subcat"><a href="#" class="menu-subcat-link">ultra premium</a></li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
Here is the SCSS code:
nav.products {
ul {
li.brown {
border-left: 10px solid #a09484;
}
li.pink {
border-left: 10px solid #9d7b8c;
}
li.green {
border-left: 10px solid #558d80;
}
li {
border-bottom: none;
padding: 1em 0;
margin-bottom: .2em;
a {} .sub-menu {
height: 0;
overflow: hidden;
.content-sub-menu {
-moz-transform: translateY(-100%);
-ms-transform: translateY(-100%);
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
-webkit-transition: transform 0.3s ease-in-out;
-o-transition: transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out;
ul.sub-menu-list {
padding-left: 1em;
li {
font-size: 1em;
margin-bottom: 0;
a {}
}
}
}
}
&.current {
.content-sub-menu {
-moz-transform: translateY(0%);
-ms-transform: translateY(0%);
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
/*DROPDOWNS*/
.sub-menu {
height: 100%;
}
/*DROPDOWNS END*/
}
}
}
}
nav.products ul li.current .sub-menu {
height: 100%;
}
And this is the script used to display the submenus:
$('.products ul li').click(function(e) {
$(this).toggleClass('current');
});