In my current project, I am implementing a navigation bar that slides a menu from right to left. When the user clicks on their profile picture, the hidden menu is revealed.
To achieve this functionality, I utilize the addition of classes hidden
and show
to toggle the visibility of the menu.
$(document).ready(function(){
$(".img-profile").click(function(){
$(".menu-wrapper").addClass("show");
});
$(".menu-bg").click(function(){
$(".menu-wrapper").removeClass("show");
});
});
CSS
.show{
display: inline-block !important;
}
.hidden{
display: none;
}
The issue arises when attempting to animate the menu using transitions. Even with the specified transition properties from transition: all 0.2s linear 0s
and transform values from 250px
to 0
, the animation does not occur as intended.
.menu-wrapper > .login-menu{
background-color: #fff;
height: 100%;
overflow-y: auto;
position: fixed;
right: 0;
width: 250px;
z-index: 5;
padding: 30px 20px;
text-align: center;
transition: all 0.2s linear 0s;
transform: translateX(0px);
}
.menu-wrapper .show > .login-menu{
transform: translateX(250px);
}
Additionally, I aim to add an animation effect for closing the menu from right to left.
You can view the complete code on JSFIDDLE