I am brand new to coding and this is my inaugural code snippet:
.container_menu {
position: relative;
top: 0px;
left: 0px;
width: 25px;
height: 25px;
}
.container_menu .line-1 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
left: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu .line-2 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
right: 0;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu:hover .line-1 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.container_menu:hover .line-2 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class="container_menu">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
Is there a way to create an animation on click instead of hover (Maybe using JS)?
I intend to implement this in a website menu.
I believe I need to utilize a JS script. However, I'm unsure how to go about it. Any assistance is greatly appreciated.
Source code available at https://codepen.io/defaultdave/pen/baXLPQ