Created
September 30, 2012 22:23
-
-
Save knorthfield/3808607 to your computer and use it in GitHub Desktop.
CSS Flip Animation
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title>CSS Flip</title> | |
<style type='text/css'> | |
/* entire container, keeps perspective */ | |
.flip-container { | |
-webkit-perspective: 1000; | |
-moz-perspective: 1000; | |
-o-perspective: 1000; | |
perspective: 1000; | |
} | |
/* flip the pane when hovered */ | |
.flip-container:hover .flipper, .flip-container.hover .flipper { | |
-webkit-transform: rotateY(180deg); | |
-moz-transform: rotateY(180deg); | |
-o-transform: rotateY(180deg); | |
transform: rotateY(180deg); | |
} | |
.flip-container, .front, .back { | |
width: 320px; | |
height: 480px; | |
} | |
/* flip speed goes here */ | |
.flipper { | |
-webkit-transition: 0.6s; | |
-webkit-transform-style: preserve-3d; | |
-moz-transition: 0.6s; | |
-moz-transform-style: preserve-3d; | |
-o-transition: 0.6s; | |
-o-transform-style: preserve-3d; | |
transition: 0.6s; | |
transform-style: preserve-3d; | |
position: relative; | |
} | |
/* hide back of pane during swap */ | |
.front, .back { | |
-webkit-backface-visibility: hidden; | |
-moz-backface-visibility: hidden; | |
-o-backface-visibility: hidden; | |
backface-visibility: hidden; | |
position: absolute; | |
top: 0; | |
left: 0; | |
background-color: #ccc; | |
} | |
/* front pane, placed above back */ | |
.front { | |
z-index: 2; | |
} | |
/* back, initially hidden pane */ | |
.back { | |
-webkit-transform: rotateY(180deg); | |
-moz-transform: rotateY(180deg); | |
-o-transform: rotateY(180deg); | |
transform: rotateY(180deg); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="flip-container" ontouchstart="this.classList.toggle('hover');"> | |
<div class="flipper"> | |
<div class="front"> | |
<!-- front content --> | |
</div> | |
<div class="back"> | |
<!-- back content --> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment