Skip to content

Instantly share code, notes, and snippets.

@jocubeit
Created March 18, 2019 01:50
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 jocubeit/a11fd877f90e12d4caa3b087e3980669 to your computer and use it in GitHub Desktop.
Save jocubeit/a11fd877f90e12d4caa3b087e3980669 to your computer and use it in GitHub Desktop.
Card Flip
<div class="card-container">
<div class="card">
<div class="front">
A
</div>
<div class="back">
B
</div>
</div>
</div>
var card = document.querySelector(".card");
var playing = false;
card.addEventListener('click',function() {
if(playing)
return;
playing = true;
anime({
targets: card,
scale: [{value: 1}, {value: 1.4}, {value: 1, delay: 250}],
rotateY: {value: '+=180', delay: 200},
easing: 'easeInOutSine',
duration: 400,
complete: function(anim){
playing = false;
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.js"></script>
body
{
background: #cfd8dc;
}
.card-container
{
font-family: 'Open Sans', sans serif;
font-size: 120px;
font-weight: bold;
width: 400px;
height: 250px;
margin: 80px auto;
border-radius: 10px;
perspective: 1400px;
}
.card
{
position: relative;
height: 100%;
border-radius: 10px;
widht: 100%;
transform-style: preserve-3d;
}
.front,
.back
{
display: flex;
width: 100%;
height: 100%;
border-radius: 10px;
justify-content: center;
align-items: center;
backface-visibility: hidden;
}
.front
{
color: #fff;
background: #2196f3;
}
.back
{
position: absolute;
top: 0;
left: 0;
transform: rotateY(180deg);
color: #2196f3;
background: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment