Created
August 24, 2013 17:19
-
-
Save dyaa/6329296 to your computer and use it in GitHub Desktop.
Easy (3D CSS card flip) example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="flip"> | |
<div class="card"> | |
<div class="face front"> | |
Front | |
</div> | |
<div class="face back"> | |
Back | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.flip').click(function(){ | |
$(this).find('.card').addClass('flipped').mouseleave(function(){ | |
$(this).removeClass('flipped'); | |
}); | |
return false; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: #ccc; | |
} | |
.flip { | |
-webkit-perspective: 800; | |
width: 400px; | |
height: 200px; | |
position: relative; | |
margin: 50px auto; | |
} | |
.flip .card.flipped { | |
-webkit-transform: rotatex(-180deg); | |
} | |
.flip .card { | |
width: 100%; | |
height: 100%; | |
-webkit-transform-style: preserve-3d; | |
-webkit-transition: 0.5s; | |
} | |
.flip .card .face { | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
-webkit-backface-visibility: hidden ; | |
z-index: 2; | |
font-family: Georgia; | |
font-size: 3em; | |
text-align: center; | |
line-height: 200px; | |
} | |
.flip .card .front { | |
position: absolute; | |
z-index: 1; | |
background: black; | |
color: white; | |
cursor: pointer; | |
} | |
.flip .card .back { | |
-webkit-transform: rotatex(-180deg); | |
background: blue; | |
background: white; | |
color: black; | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment