Last active
October 4, 2017 13:57
-
-
Save carolina-vallejo/f611ba06d8516e32afee7afbada2dd08 to your computer and use it in GitHub Desktop.
flip cards in css onclick
This file contains hidden or 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="flip-container" onclick="this.classList.toggle('hover');"> | |
<div class="flipper"> | |
<div class="inner-card"> | |
<div class="front"> | |
aa | |
</div> | |
<div class="back"> | |
bb | |
</div> | |
</div> | |
<!-- .inner-card --> | |
</div> | |
<!-- .flipper --> | |
</div> |
This file contains hidden or 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-container').on('click', function() { | |
var $this = $(this); | |
$this.toggleClass('hover'); | |
if ($this.hasClass('changed')) { | |
$this.removeClass('changed'); | |
} else { | |
setTimeout(function() { | |
$this.toggleClass('changed'); | |
console.log('ccc'); | |
}, 600); | |
} | |
}); |
This file contains hidden or 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
///////////////// | |
// ONLY FLIP | |
//////////////// | |
.flip-container { | |
cursor: pointer; | |
perspective: 1000px; | |
-webkit-perspective: 1000px; | |
.flipper { | |
transition: 0.6s; | |
-webkit-transform-style: preserve-3d; | |
-ms-transform-style: preserve-3d; | |
transform-style: preserve-3d; | |
position: relative; | |
@include transform(perspective(1000px) rotateY(0deg)); | |
} | |
.front, | |
.back { | |
width: 100%; | |
backface-visibility: hidden; | |
-webkit-backface-visibility: hidden; | |
top: 0; | |
left: 0; | |
} | |
.front { | |
position: relative; | |
@include transform(perspective(1000px) rotateY(0deg)); | |
} | |
.back { | |
position: absolute; | |
@include transform(perspective(1000px) rotateY(-180deg)); | |
} | |
&.hover .flipper { | |
@include transform(perspective(1000px) rotateY(-180deg)); | |
} | |
&.changed { | |
.back { | |
backface-visibility: visible; | |
-webkit-backface-visibility: visible; | |
} | |
} | |
} //---end flipcontainer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment