In this tutorial, we will be creating a side menu bar using JavaScript. The side
menu bar will allow users to easily navigate through your website and access
different pages and content. We will start by setting up the HTML and CSS for
the side menu bar, and then we will use JavaScript to add the functionality to
toggle the menu bar open and closed. By the end of this tutorial, you will have
a fully functional side menu bar that can be easily added to any website.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<title>Tutorial 8</title>
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<script type="text/javascript" src="js/sidemenubar.js"></script>
</head>
<body>
<div id="mySidemenu" class="sidemenu">
<a href="javascript:void(0)" class="close" onclick="closeSM()">×</a>
<div class="sm-wrapper">
<a href="#">HOME</a>
<a href="#">PORTFOLIOS</a>
<a href="#">ABOUT</a>
<a href="#">CONTACT</a>
</div>
</div>
<div id="pg-content">
<div style="font-size:50px;cursor:pointer;color:#5b5b5b" onclick="openSM()">☰</div>
<h1>SIDE MENU<br/><span>TUTORIAL</span></h1>
</div>
</body>
</html>
body{
margin: 0;
overflow: hidden;
background-color: #eae7dc;
}
/* SIDE MENU PART */
.sm-wrapper{
margin-top: 100px;
}
.sidemenu{
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #d8c3a5;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidemenu a{
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 45px;
font-family: 'inconsolata', monospace;
color: #ffffff;
display: block;
letter-spacing: 5px;
margin-bottom: 20px;
transition: 0.3s;
}
.sidemenu .close{
position: absolute;
top: 0;
right: 25px;
font-size: 95px;
margin-left: 50px;
}
/* SIDE MENU HOVER EFFECT */
.sm-wrapper a:after{
z-index: -1;
position: absolute;
left: 0%;
width: 0;
height: 50px;
background: #e85e4f;
content: '';
transition: width 0.35s ease-in-out;
}
.sm-wrapper a:hover:after{
width: 10%;
}
.sm-wrapper a:hover{
padding-left: 64px;
transition: 0.35s ease-in-out;
}
/* CONTENT PART */
#pg-content{
transition: margin-left 0.5s;
padding: 16px;
}
h1{
font-family: "inconsolata", monospace;
font-size: 10em;
text-align: center;
letter-spacing: 50px;
padding: 100px 0px 100px 25px;
color: #5b5b5b;
}
span{
letter-spacing: 50px;
padding-left: 44px;
color: #e85e4f;
}
function openSM(){
document.getElementById("mySidemenu").style.width ="450px";
document.getElementById("pg-content").style.marginLeft = "450px";
}
function closeSM(){
document.getElementById("mySidemenu").style.width = "0";
document.getElementById("pg-content").style.marginLeft ="0";
}
Watch Full Video Here!
Comments
Post a Comment