Created
April 5, 2017 16:37
-
-
Save imliam/8b26fa8ed8cb00d525e5760d45c4c6e5 to your computer and use it in GitHub Desktop.
Flip an Element
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
/* 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); | |
} |
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 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> |
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
$('[data-flip]').on('click', function() { | |
var toFlip = $(this).attr('data-flip'); | |
$(toFlip).toggleClass('flip'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/somo0qwt/3/