DeshAmarBD
Home » Web Design » Navbar Menu Toggle Effect JavaScript

Navbar Menu Toggle Effect JavaScript

To create a Mobile Toggle Navigation Menu you need HTML, CSS, and JavaScript. Are you looking for inspiring effects and interaction ideas for your site?

HTML:

<nav class="navbar">
  <div class="menuToggle"></div>
</nav>

CSS:

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: sans-serif;
}
body{
  background-color: #3d4152;
}
.navbar{
  position: relative;
  padding-left: 20px;
  padding-right: 20px;
  background-color: #fff;
  transition: 0.3s;
  display: flex;
}
.navbar .menuToggle{
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 30px;
  width: 100%;
}
.navbar .menuToggle::before{
  content: "";
  width: 20px;
  height: 2px;
  background-color: #3d4152;
  transform: translateY(-8px);
  transition: 0.5s;
}
.navbar.open .menuToggle::before{
  transform: translateY(0px) rotate(45deg);
  width: 30px;
}
.navbar .menuToggle::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 2px;
  background: #3d4152;
  transform: translateY(8px);
  transition: 0.5s;
  box-shadow: 0 -8px 0 #3d4152;
}
.navbar.open .menuToggle::after {
  transform: translateY(0px) rotate(-45deg);
  box-shadow: 0 0 0 #3d4152;
}

JavaScript:

const menuToggle = document.querySelector('.menuToggle');
const navbar = document.querySelector('.navbar');

		menuToggle.onclick = function(){
navbar.classList.toggle('open')
		}

RH Suman

Add comment

Leave a Reply

AdBlocker Message

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.