My toggled class rotates an element clockwise on 180 degrees when assigned. How can I modify my css to rotate an element from 180 to 0 degrees clockwise when toggled class removes?
var el = document.getElementById("wrapper");
el.addEventListener("click", function(){
this.classList.toggle("toggled");
});
#wrapper {
position: relative;
top: 20px;
left: 20px;
padding: 10px;
cursor: pointer;
display: inline-block;
}
#wrapper.toggled {
transform: rotateZ(180deg);
}
#wrapper > div {
width: 35px;
height: 3px;
margin-bottom: 10px;
background-color: #3f51b5;
}
#wrapper > div:last-child {
margin-bottom: 0;
}
#wrapper, #wrapper > div {
transition-property: transform;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0.35, 0, 0.25, 1);
}
#wrapper.toggled >div:first-child {
transform: rotateZ(45deg) rotateY(45deg) translateX(14px) translateY(-3px);
}
#wrapper.toggled >div:last-child {
transform: rotateZ(-45deg) rotateY(45deg) translateY(3px) translateX(14px);
}
<div id="wrapper">
<div></div>
<div></div>
<div></div>
</div>
I did some edits on your script and style and it work fine : https://jsfiddle.net/IA7medd/rkk0zc8k/
HTML:
css:
the script:
Another Solution :
And this is another option but using jquery : https://jsfiddle.net/IA7medd/pr9akayk/
in the option you will need only to change your script like this :