I am new to web development and I am having trouble making a transition speed to open and close this side menu. The menu opens instantly even after adding a transition to the CSS and a duration to the Javascript. I did research before coming here, but nothing seemed to work. If one of ya'll could help out, that would be wonderful.
function openNav() {
document.getElementById("mySidepanel").style.width = "250px";
document.getElementById("mySidepanel").style.transitionDuration = "0.5s";
document.getElementById("mySidepanel").style.display = "block";
document.getElementById("openbtn").style.display = 'none';
}
function closeNav() {
document.getElementById("mySidepanel").style.width = "0";
document.getElementById("mySidepanel").style.transitionDuration = "0.5s";
document.getElementById("mySidepanel").style.display = "none";
document.getElementById("openbtn").style.display = "inline-block";
}
/** Navigation Bar **/
.sidepanel {
width: 0;
position: fixed;
z-index: 1;
height: 100%;
top: 0;
right: 0;
background-color: rgba(17, 17, 17, 0.425);
overflow-x: hidden;
padding-top: 60px;
transition: all 0.5s ease-in-out;
}
.sidepanel a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
font-family: "lato", sans-serif;
color: #818181;
display: block;
}
.sidepanel a:hover {
color: #f1f1f1;
}
.sidepanel #closebtn {
position: absolute;
top: 10px;
right: 20px;
font-size: 36px;
margin-left: 50px;
}
#openbtn {
font-size: 30px;
cursor: pointer;
background: -webkit-linear-gradient(white, #38495a);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
padding: 10px 15px;
border: none;
float: right;
}
#openbtn:hover {
background: -webkit-linear-gradient(#748df0c9, #324dbbc9);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
a:hover .fas {
color: #3e5ddac9;
text-shadow: 0 0 5px #3e5ddac9;
}
a:hover .far {
color: #3e5ddac9;
text-shadow: 0 0 5px #3e5ddac9;
}
<div id="mySidepanel" class="sidepanel" style="display: none;">
<a href="javascript:void(0)" id="closebtn" onclick="closeNav()">×</a>
<a href="/"><i class="fas fa-home"></i></span> Home</a>
<a href="emojis.html"><i class="far fa-laugh-beam"></i> Emojis</a>
</div>
<button id="openbtn" onclick="openNav()">☰</button>
The javascript is to hide and show the open button when the sidebar is visible. I tried to set a transitionDuration with it, but that also didn't work.