I have successfully implemented a script to open my hamburger menu. However, I am facing an issue with subitems as some list items contain them. How can I modify the script to ensure that the subitems expand when clicked instead of just hovering?
function myResponsive() {
var x = document.getElementById("myMenu");
if (x.className === "menu-hori") {
x.className += " responsive";
} else {
x.className = "menu-hori";
}
}
.menu-hori{
width: 1100px;
margin: auto;
height: auto;
margin-top: 15px;
padding: 0px;
display: table;
z-index: 100;
background: grey;
}
.menu-hori ul {
margin: 0;
padding: 0;
list-style: none;
}
.menu-hori ul ul {
opacity: 0;
position: absolute;
top: 160%;
visibility: hidden;
transition: all .4s ease;
-webkit-transition: all .4s ease;
}
.menu-hori ul ul ul {
top: 0%;
left: 160%;
}
.menu-hori ul ul li:hover > ul {
top: 0%;
left: 100%;
opacity: 1;
visibility: visible;
}
.menu-hori ul li:hover > ul {
opacity: 1;
top: 100%;
visibility: visible;
}
.menu-hori ul li {
float: left;
position: relative;
}
.menu-hori ul ul li { float: none; }
.menu-hori ul li {
background-color: grey;
cursor: pointer;
}
.menu-hori ul a {
text-decoration: none;
display: block;
color: white;
padding: 10px 15px;
width: auto;
min-width: 100px;
text-align: center;
text-shadow: 0px -1px 0px rgba(0,0,0,.2);
}
.menu-hori ul li:hover { background-color: #069CDE; }
.menu-hori ul li a:hover { background-color: #069CDE; }
.menu-hori span.dropBottom,span.dropRight {
display: block;
box-shadow: inset 2px 0px 0px #069CDE;
position: absolute;
left: 0px;
width: 100%;
height: 100%;
top: 0px;
}
.menu-hori span.dropBottom {
box-shadow: inset 0px 2px 0px #069CDE;
position: absolute;
width: 100%;
bottom: 0px;
}
.menu-hori a:hover {
background-color: #ddd;
color: black;
}
.menu-hori .icon {
display: none;
}
@media screen and (max-width: 1100px) {
.menu-hori{
width: 100%;
min-height: 40px;
height: auto;
margin-top: 15px;
padding: 0px;
display: table;
z-index: 100;
background: grey;
display: block;
}
}
@media screen and (max-width: 1100px) {
.menu-hori ul li{
float: none;
}
.menu-hori ul li a{
display: none;
}
.menu-hori ul li a.icon{
display: block;
text-align: right;
}
.responsive ul li a{
display: block;
}
}
<div class="menu-hori" id="myMenu">
<ul>
<li><a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myResponsive()">☰</a></li>
<li><a>BEVEILIGINGSCAMERA</a><span class="dropBottom"></span>
<ul>
<li><a href="#" class="dropRight">Analoog</a>
<ul>
<li><a href="#">irc10</a></li>
<li><a href="#">ird29</a></li>
<li><a href="#">ird1</a></li>
</ul>
</li>
</ul>
</li>
</div>
I have provided the code snippet for better context. It seems like a lot now, but I need to refine my JavaScript so that clicking on list items will also expand the sub items instead of just hovering over them as it currently does.