Skip to content

Instantly share code, notes, and snippets.

@ozzieperez
Last active December 14, 2015 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzieperez/5042927 to your computer and use it in GitHub Desktop.
Save ozzieperez/5042927 to your computer and use it in GitHub Desktop.
Flip Card With Graceful Degradation. Dependencies jQuery and Modernizr (can be optional). The only thing used from Modernizr is it looks for the "csstransforms3d" class to handle degradation.
<html class="csstransforms3d">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<style>
/* CARDS
*****************************************************/
.card {
/* styling */
width: 200px;
height: 200px;
margin: 20px;
border: 1px solid #ccc;
float: left;
position: relative;
overflow: hidden;
}
.csstransforms3d .card{
border: none;
overflow: visible;
-webkit-perspective: 600px;
-moz-perspective: 600px;
}
.card .front {
/* styling */
width: 200px;
height: 200px;
background: #efefef;
border-bottom:1px solid #ccc;
-moz-box-shadow: 0 1px 5px rgba(0,0,0,0.9);
-webkit-box-shadow: 0 1px 5px rgba(0,0,0,0.9);
box-shadow: 0 1px 5px rgba(0,0,0,0.9);
top: 0;
left: 0;
z-index: 900;
float: none;
position: absolute;
-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;
}
.csstransforms3d .card .front {
/* styling */
border: 1px solid #ccc;
-webkit-transform: rotateX(0deg) rotateY(0deg);
-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
-moz-transform: rotateX(0deg) rotateY(0deg);
-moz-transform-style: preserve-3d;
-moz-backface-visibility: hidden;
}
.card.flip .front {
/* styling */
-moz-box-shadow: 0 15px 50px rgba(0,0,0,0.2);
-webkit-box-shadow: 0 15px 50px rgba(0,0,0,0.2);
box-shadow: 0 15px 50px rgba(0,0,0,0.2);
z-index: 900;
}
.csstransforms3d .card.flip .front {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
}
.card .back {
/* styling */
width: 200px;
height: 200px;
background: #fff;
/* DO NOT REMOVE: This is content padding for when it slides up (no flip) */
padding-top: 10px;
float: none;
position: absolute;
top: 0;
left: 0;
z-index: 800;
-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;
}
.csstransforms3d .card .back {
/* styling */
border: 1px solid #ccc;
padding-top: 0; /* overwrites the fallback when supported */
-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;
}
.card.flip .back {
/* styling */
box-shadow: 0 15px 50px rgba(0,0,0,0.2);
-moz-box-shadow: 0 15px 50px rgba(0,0,0,0.2);
-webkit-box-shadow: 0 15px 50px rgba(0,0,0,0.2);
z-index: 1000;
}
.csstransforms3d .card.flip .back {
-webkit-transform: rotateX(0deg) rotateY(0deg);
-moz-transform: rotateX(0deg) rotateY(0deg);
}
</style>
<script type="text/javascript">
$(document).ready(function(){
if($("html").hasClass("csstransforms3d")){
$('.card').hover(function(){
$(this).addClass('flip');
},function(){
$(this).removeClass('flip');
});
} else{
$('.card').hover(function(){
$(this).find(".front").animate({top: -190}, 'fast');
},function(){
$(this).find(".front").animate({top: 0}, 'fast');
});
}
});
</script>
</head>
<body>
<div class="card">
<div class="front">
<h2>Front</h2>
</div>
<div class="back">
<h2>Back</h2>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment