Created
August 11, 2010 10:10
-
-
Save mattdenner/518776 to your computer and use it in GitHub Desktop.
How to do backface hiding when -webkit-backface-visibility doesn't work!
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
/* | |
The back of the card is rotated 180 degrees from the card itself, giving | |
the illusion that it really is the back! Unfortunately hiding the back | |
face of both "faces" doesn't work with webkit builds (requires Snow Leopard!) | |
but we set it anyway. | |
*/ | |
.card #back { -webkit-transform: rotateY(180deg); } | |
.card .face { -webkit-backface-visibility: hidden; } | |
/* | |
Flipping the '.card' is simple, just rotate it 180 degrees. | |
*/ | |
.card { | |
-webkit-transform-style: preserve-3d; | |
-webkit-transition-property: all; | |
-webkit-transition-timing-function: linear; | |
} | |
.card:hover { | |
-webkit-transform: rotateY(180deg); | |
} | |
/* | |
Flipping the faces is not so simple when the browser doesn't support the | |
'-webkit-backface-visibility' property correctly! We have to fake it so | |
that the opacity of the '.face' changes such that, when it's at 90 degrees | |
rotation, the opacity is 0. | |
The transition from opacity 1 to 0, or vice-versa, is quick but delayed | |
in both directions for the face that is being revealed. In other words, as | |
the front face nears 90 degrees on its way to the back, it suddenly changes | |
its opacity. As the back face, coming from back to front, passes 90 degrees | |
it suddenly increases it opacity. | |
*/ | |
.card .face { | |
-webkit-transition-property: opacity; | |
-webkit-transition-timing-function: linear; | |
} | |
.card:hover #back, .card #front { opacity: 1; } | |
.card:hover #front, .card #back { opacity: 0; } | |
/* To make it easier to manage, timings are in one big block here! */ | |
.card { -webkit-transition-duration: 2.0s; } /* 100% */ | |
.card .face { -webkit-transition-duration: 0.2s; } /* 10% */ | |
.card:hover #back, .card #front { -webkit-transition-delay: 1.0s; } /* 50% */ | |
.card:hover #front, .card #back { -webkit-transition-delay: 0.8s; } /* 40% */ |
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="card"> | |
<!-- This div is only here to ensure that the inner '.face' elements obey the padding of the '.card' --> | |
<div> | |
<div id="front" class="face"> | |
<h1>Front!</h1> | |
</div> | |
<div id="back" class="face"> | |
<h1>Back!</h1> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment