How to create Simple Mobile Toggle menu using css and Jquery

Mobile toggle menu is simple way to display the links(menus) in mobile devices. Today i will explain about how to create the toggle menu and how to set this toggle menu to the mobile resolution. First you should set the two different navigation with same links then using media query set the normal menu to Min-width:760px set mobile menu to max-width:759px resolution

For example
use media query like below
@media only screen and (max-width: 759px) {
    .mobile-menu {
        display:block;
    }

.normal-menu {
        display:none;
    }
}

@media only screen and (min-width: 759px) {
    .mobile-menu {
        display:none;
    }

.normal-menu {
        display:block;
    }
}

So you will hide the normal menu and display the mobile menu in mobile resolution, The same process you will hide mobile menu and display the normal menu in desktop resolution.You can able to fix the menu like this. In this example i given only mobile menu, Here we have the demo page and full source code. You can download and use it. I hope this post is useful.

Source Code for Mobile Menu using Jquery:

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Mobile toggle menu using jquery</title>
  
<style>
#toggle {
  display: block;
  width: 45px;
  height: 32px;
  margin: 30px auto 10px;
}

#toggle span:after,
#toggle span:before {
  content: "";
  position: absolute;
  left: 0;
  top: -9px;
}
#toggle span:after{
  top: 9px;
}
#toggle span {
  position: relative;
  display: block;
}

#toggle span,
#toggle span:after,
#toggle span:before {
  width: 100%;
  height: 5px;
  background-color: #851abc;
  transition: all 0.3s;
  backface-visibility: hidden;
  border-radius: 2px;
}

#toggle.on span {
  background-color: transparent;
}
#toggle.on span:before {
  transform: rotate(45deg) translate(5px, 5px);
}
#toggle.on span:after {
  transform: rotate(-45deg) translate(7px, -8px);
}
#toggle.on + #menu {
  opacity: 1;
  visibility: visible;
}

#menu {
  position: relative;
  color: #999;
  width: 290px;
  padding: 10px;
  margin: auto;
  font-family: "Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif;
  text-align: center;
  border-radius: 4px;
  background: white;
  box-shadow: 0 1px 8px rgba(0,0,0,0.05);
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s;
  border: 1px solid #ccc;
}
#menu:after {
  position: absolute;
  top: -15px;
  left: 95px;
  content: "";
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 20px solid white; 
  display:none;
}
#menu ul, li, li a {
  list-style: none;
  display: block;
  margin: 0;
  padding: 0;
}
#menu li a {
  padding: 5px;
  color: #888;
  text-decoration: none;
  transition: all .2s;
}
#menu li a:hover,
#menu li a:focus {
  background: #851abc;
  color: #fff;
}
    </style>

</head>
<body>
<a href="#menu" id="toggle"><span></span></a>
<div id="menu">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About us</a></li>
<li><a href="#gallery">Gallery</a></li>
<li><a href="#contact">Contact us</a></li>
</ul>
</div>
<script src="js/new-mob-menu.js"></script>
</body>
</html>

Post a Comment

0 Comments