Skip to content

Instantly share code, notes, and snippets.

@imliam
Created April 5, 2017 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imliam/8b26fa8ed8cb00d525e5760d45c4c6e5 to your computer and use it in GitHub Desktop.
Save imliam/8b26fa8ed8cb00d525e5760d45c4c6e5 to your computer and use it in GitHub Desktop.
Flip an Element
/* entire container, keeps perspective */
.flip-container {
perspective: 1000px;
}
/* flip speed goes here */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
}
/* hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
width: 100%;
position: absolute;
top: 0;
left: 0;
}
/* front pane, placed above back */
.front {
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
transform: rotateY(180deg);
}
.flip-container.flip .flipper {
transform: rotateY(180deg);
}
<!--
|--------------------------------------------------------------------------
| Flip an Element
|--------------------------------------------------------------------------
|
| Gives the ability to "flip" an element to make it look as if it has two
| faces by clicking on an element with a data-flip="selector" attribute.
|
-->
<div class="flip-container" id="myCard">
<div class="flipper">
<div class="front">
<div class="card">
<img class="card-img-top" src="https://placehold.it/500x100" alt="Card image cap">
<div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary" data-flip="#myCard">Flip to back</a>
</div>
</div>
</div>
<div class="back">
<div class="card text-center">
<div class="card-header">
Featured
</div>
<div class="card-block">
<h4 class="card-title">Special title treatment</h4>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary" data-flip="#myCard">Flip to front</a>
</div>
<div class="card-footer text-muted">
2 days ago
</div>
</div>
</div>
</div>
</div>
$('[data-flip]').on('click', function() {
var toFlip = $(this).attr('data-flip');
$(toFlip).toggleClass('flip');
})
@imliam
Copy link
Author

imliam commented Apr 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment