Created
May 11, 2016 10:29
-
-
Save zdying/0de0e82cd4094cb173304a534743d739 to your computer and use it in GitHub Desktop.
css3 flip
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Flip</title> | |
<style> | |
.row{ | |
display: block; | |
clear: both | |
} | |
.container{ | |
perspective: 800px; | |
width: 110px; | |
height: 110px; | |
display: inline-block; | |
cursor: default; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
-webkit-font-smoothing: antialiased; | |
} | |
.card{ | |
position: relative; | |
width: 100%; | |
height: 100%; | |
transition: all .6s ease; | |
-webkit-transform-style: preserve-3d; | |
-moz-transform-style: preserve-3d; | |
-ms-transform-style: preserve-3d; | |
transform-style: preserve-3d; | |
} | |
.container:hover .card{ | |
transform: rotateY(180deg); | |
} | |
.container:hover .card.v{ | |
transform: rotateX(180deg); | |
} | |
.content{ | |
height: 100%; | |
width: 100%; | |
position: absolute; | |
left: 0; | |
top: 0; | |
backface-visibility: hidden; | |
transform: translate3d(0,0,0); | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
font-size: 60px; | |
color: #FFF; | |
} | |
.back{ | |
background: red; | |
transform: rotateY(180deg); | |
} | |
.v .back{ | |
background: red; | |
transform: rotateX(180deg); | |
} | |
.front{ | |
z-index: 2; | |
background: blue; | |
} | |
.grid { | |
display: flex; | |
width: 330px; | |
height: 330px; | |
flex-wrap: wrap; | |
} | |
.grid .container{ | |
width: 110px; | |
height: 110px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="grid" id="grid" style=""> | |
</div> | |
<script> | |
var len = 9; | |
var color = [ | |
'#16a085', '#27ae60', '#2980b9', | |
'#f1c40f', '#e67e22', '#e74c3c', | |
'#f39c12', '#d35400', '#c0392b' | |
]; | |
var cls = [ | |
'v', '', 'v', | |
'', '', '', | |
'v', '', 'v' | |
]; | |
var html = []; | |
for(var i = 0; i < len; i++){ | |
html.push( | |
`<div class="container"> | |
<div class="card ${cls[i]}"> | |
<div class="content front" style="background: ${color[i]}">${i + 1}</div> | |
<div class="content back">:)</div> | |
</div> | |
</div>` | |
); | |
} | |
document.getElementById('grid').innerHTML = html.join('') | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment