javascript dropdown mobile-nav

In this example below you will see how to do a javascript dropdown mobile-nav with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 1zm0, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 1zm0 ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>javascript dropdown mobile-nav</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="hamburger">
  <span></span>
  <span></span>
  <span></span>
</div>  



  <ul id="list">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Profile</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/1zm0/javascript-dropdown-mobile-nav-zjzOoB */
#hamburger {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 35px;
}

span {
  width: 50px;
  height: 5px;
  margin: 3px;
  background-color: black;
  border-radius: 15px;
}

ul.yay {
  display: flex;
  flex-direction: column;
  opacity: 1;
  list-style-type: none;
  width: 55px;
  transition: .25s ease-in-out;
  margin: 0;
  padding: 0;
  margin-top: 10px;
  justify-content: flex-start;
  align-items: flex-start;
}
ul li a {
  text-decoration: none;
  color: black;
}
ul li a:hover {
  color: green;
}
ul {
  opacity: 0;
}



/*Downloaded from https://www.codeseek.co/1zm0/javascript-dropdown-mobile-nav-zjzOoB */
var hamburger = document.getElementById("hamburger");
var element = document.getElementById("list");

hamburger.addEventListener("click", function() {
  element.classList.toggle("yay");
  
});

Comments