I've been struggling to implement a functional and visually appealing hamburger menu on my website. The challenge lies in integrating the menu seamlessly into the page rather than having it just pop up abruptly.
Despite trying various webkit tools, I can't seem to achieve the desired animation effect with the bar elements only triggering once.
Menu.style.display = "none";
function ShowHide(x) {
x.classList.toggle("change");
var Menu = document.getElementById("Menu");
if (Menu.style.display === "none") {
Menu.style.display = "block";
} else {
Menu.style.display = "none";
}
}
.container {
display: inline-block;
cursor: pointer;
}
.bar1,
.bar2,
.bar3 {
width: 35px;
height: 5px;
background-color: #333;
margin: 6px 0;
transition: 0.4s;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px);
transform: rotate(-45deg) translate(-9px, 6px);
}
.change .bar2 {
opacity: 0;
}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px);
transform: rotate(45deg) translate(-8px, -8px);
}
}
body {
background-color: rgb(209, 224, 224);
}
.Menu {
width: 150px;
background-color: rgb(208, 208, 225);
display: none
}
<div class="container" onclick="ShowHide(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<div id="Menu" style="width: 150px; background-color: rgb(208, 208, 225); display: none;">
<h2><a href="Homepage.html">Homepage</a></h2>
<br>
<h2><a href="Subpage1.html">Subpage 1</a></h2>
<br>
<h2><a href="Subpage2.html">Subpage 2</a></h2>
<br>
<h2><a href="Subpage3.html">Subpage 3</a></h2>
<br>
<h2><a href="Subpage4.html">Subpage 4</a></h2>
<br>
<h2><a href="Subpage5.html">Subpage 5</a></h2>
<br>
</div>