Easy "3D CSS card flip" example
Let's see a very very basic integration of the awesome "card flip" effect with simple CSS3 properties.
Feel free to use/share/contribute.
HTML
<div class="flip">
<div class="card">
<div class="face front">
Front
</div>
<div class="face back">
Back<br/>
sdfgsdfg
</div>
</div>
</div>
CSS
body {
background: #ccc;
}
.flip {
-webkit-perspective: 800;
width: 400px;
position: relative;
margin: 50px auto;
}
.flip .card.flipped {
-webkit-transform: rotatex(-180deg);
}
.flip .card {
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: 0.5s;
}
.flip .card .face {
width: 100%;
position: absolute;
-webkit-backface-visibility: hidden ;
z-index: 2;
font-family: Georgia;
font-size: 3em;
text-align: center;
cursor: pointer;
}
.flip .card .front {
z-index: 1;
background: black;
color: white;
}
.flip .card .back {
-webkit-transform: rotatex(-180deg);
background: white;
color: black;
}
JavaScript
$('.flip').hover(function(){
$(this).find('.card').addClass('flipped');
return false;
}).mouseleave(function () {
$('.flip > .card').removeClass('flipped');
});
var frontHeight = $('.front').outerHeight();
var backHeight = $('.back').outerHeight();
if (frontHeight > backHeight) {
$('.flip, .back').height(frontHeight);
}
else if (frontHeight > backHeight) {
$('.flip, .front').height(backHeight);
}
else {
$('.flip').height(backHeight);
}