I am wondering how to create an animation that would transform a 3 lined menu into a cross. The structure of the following buttons is sketched on the picture above. The 3 lines are created using 3 spans and the cross is created using before and after elements and rotate transition. Now I only use jquery to toggle class that changes the look of the button, but I would like to achieve some nice, animated effect such as
- one line of the 3-lined menu dissapears
- the rest 2 lines rotates and creates the cross
and of course, inverse process when going from cross to 3-lined menu.
How to achieve that?
Here's the fiddle http://jsfiddle.net/eaNEE/65/
HTML:
<div id="menu-toggle-btn">
<span></span>
<span></span>
<span></span>
</div>
SASS:
#menu-toggle-btn {
margin: 15px 10px;
width: 30px;
cursor: pointer;
left: 15px;
z-index: 10;
&.js-transform {
span {
display: none !important;
}
&:before, &:after {
content: "";
width: 4px;
height: 25px;
display: block;
background: #1d1d1b;
}
&:before {
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
}
&:after {
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
margin-top: -25px;
}
}
span {
display: block;
background: #1d1d1b;
height: 4px;
width: 30px;
margin: 5px;
}
}
Here's the fiddle http://jsfiddle.net/uwozd36q/1/
HTML:
SASS:
jQuery: