I've been trying to figure out how to make a menu button that functions similarly to that of YouTube, where once clicked the rest of the page is darker and inaccessible until the button is clicked once more and the menu retracts. If anyone could help with this, I would greatly appreciate it. (and if possible, still retaining most or all of my original code). :)
menuBtn = document.getElementsByClassName('menuButton')[0];
menuBtn.addEventListener('click', function() {
menu = document.getElementsByClassName('linkList')[0];
menu.style.webkitTransition = '0.6s';
if (menu.style.right == '0px') {
menu.style.right = '-150px';
} else {
menu.style.right = '0px';
}
});
/* headerBar */
.headerBar {
position: absolute;
width: 100%;
height: 80px;
top: 0px;
left: 0px;
background-color: #b0b0b0;
}
/* headerStrip */
.headerStrip {
position: absolute;
width: 100%;
height: 5px;
top: 80px;
left: 0px;
background-color: #5e00bc
}
/* bodyBar */
.bodyBar {
position: absolute;
width: 100%;
height: 100%;
top: 85px;
left: 0px;
background-color: #000000
}
/* jobLinks styles */
.jobLinks {
text-decoration: none;
list-style: none;
}
.find {
position: absolute;
width: 80px;
height: 40px;
top: 30px;
left: 300px;
font-family: 'comfortaa';
font-size: 18px;
font-weight: 800;
color: #000000;
text-decoration: none;
text-align: center;
transition: ease-out 0.4s;
background-color: #e0e0e0;
}
.find:hover {
color: #5e00bc;
}
/* menu styles */
.menuButton {
position: absolute;
width: 30px;
height: 30px;
top: 25px;
left: 1303px;
border: none;
outline: none;
transition: ease-out 0.5s;
background-image: url('/Images/Menu_Icon.png');
background-color: #e0e0e0;
cursor: pointer;
}
.links {
font-family: 'comfortaa';
font-size: 18px;
font-weight: 500;
color: #000000;
text-decoration: none;
transition: ease-out 0.4s;
}
.links:hover {
color: #5e00bc;
}
.linkList {
position: fixed;
width: 150px;
height: 100%;
right: -150px;
top: 85px;
transition: ease-out 0.5s;
background: #e0e0e0;
}
.linkList ul li {
list-style: none;
padding: 15px;
}
.menuButton:focus~.linkList {
right: 0px;
}
<div class='headerBar'>
</div>
<div class='headerStrip'>
</div>
<div class='bodyBar'>
</div>
<div class='jobLinks'>
<li><a class='find' href='#'>Find</a></li>
</div>
<div class='menu'>
<button class='menuButton'></button>
<div class='linkList'>
<ul>
<li><a class='links' href='#'>Link 1</a></li>
<li><a class='links' href='#'>Link 2</a></li>
<li><a class='links' href='#'>Link 3</a></li>
<li><a class='links' href='#'>Link 4</a></li>
<li><a class='links' href='#'>Link 5</a></li>
<li><a class='links' href='#'>Link 6</a></li>
<li><a class='links' href='#'>Link 7</a></li>
</ul>
</div>
</div>