JSFiddle - React, Tailwind, and code Playground
by Oski Krawczyk
HTML
<div class="panel">
<div class="front go">
</div>
<div class="back">
</div>
</div>
CSS
.panel {
width: 200px;
height: 200px;
-webkit-perspective: 600;
-moz-perspective: 600;
}
.panel .front {
z-index: 900;
width: inherit;
height: inherit;
background: green;
-webkit-transform: rotateY(0deg);
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-transform: rotateY(0deg);
-moz-transform-style: preserve-3d;
-moz-backface-visibility: hidden;
/* -- transition is the magic sauce for animation -- */
-o-transition: all .4s ease-in-out;
-ms-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.panel.flip .front {
z-index: 900;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
}
.panel .back {
position: absolute;
top: 0;
left: 0;
z-index: 800;
width: inherit;
height: inherit;
background: red;
-webkit-transform: rotateY(-180deg);
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-transform: rotateY(-180deg);
-moz-transform-style: preserve-3d;
-moz-backface-visibility: hidden;
/* -- transition is the magic sauce for animation -- */
-o-transition: all .4s ease-in-out;
-ms-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.panel.flip .back {
z-index: 1000;
-webkit-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
}
JavaScript
$$('.go').addEvent('click', function(e) {
$$('.panel').addClass('flip');
e.stop();
});
$$('.back').addEvent('click', function(e) {
$$('.panel').removeClass('flip');
e.stop();
});