JSFiddle - React, Tailwind, and code Playground
HTML
<a id="toggle-menu" class="hidden">
<div>
<span class="top"></span>
<span class="middle"></span>
<span class="bottom"></span>
</div>
</a>
CSS
#toggle-menu {
display: block;
width: 15px;
height: 15px;
padding: 20px;
cursor: pointer;
}
#toggle-menu div {
width: 15px;
height: 15px;
position: relative;
}
#toggle-menu span {
display: block;
width: 15px;
height: 3px;
background: black;
position: absolute;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
#toggle-menu span.top {
top: 0px;
}
#toggle-menu span.middle {
top: 6px;
}
#toggle-menu span.bottom {
top: 12px;
}
#toggle-menu.visible span.top {
-webkit-animation: inTop 0.8s forwards;
-moz-animation: inTop 0.8s forwards;
animation: inTop 0.8s forwards;
}
#toggle-menu.visible span.middle {
-webkit-animation: inMiddle 0.8s forwards;
-moz-animation: inMiddle 0.8s forwards;
animation: inMiddle 0.8s forwards;
}
#toggle-menu.visible span.bottom {
-webkit-animation: inBottom 0.8s forwards;
-moz-animation: inBottom 0.8s forwards;
animation: inBottom 0.8s forwards;
}
#toggle-menu.hidden span.top {
-webkit-animation: outTop 0.8s backwards;
-webkit-animation-direction: reverse;
-moz-animation: outTop 0.8s backwards;
-moz-animation-direction: reverse;
animation: outTop 0.8s backwards;
animation-direction: reverse;
}
#toggle-menu.hidden span.middle {
-webkit-animation: outMiddle 0.8s backwards;
-webkit-animation-direction: reverse;
-moz-animation: outMiddle 0.8s backwards;
-moz-animation-direction: reverse;
animation: outMiddle 0.8s backwards;
animation-direction: reverse;
}
#toggle-menu.hidden span.bottom {
-webkit-animation: outBottom 0.8s backwards;
-webkit-animation-direction: reverse;
-moz-animation: outBottom 0.8s backwards;
-moz-animation-direction: reverse;
animation: outBottom 0.8s backwards;
animation-direction: reverse;
}
@-webkit-keyframes inMiddle {
50% {
-webkit-transform: rotate(0deg);
}
...
JavaScript
$('#toggle-menu').click(function(){
$(this).toggleClass('visible').toggleClass('hidden');
});