JSFiddle - React, Tailwind, and code Playground
by gregir
HTML
<div id="experiment">
<div id="cube">
<div class="face one">
1
</div>
<div class="face two">
2
</div>
<div class="face three">
3
</div>
<div class="face four">
4
</div>
<div class="face five">
5
</div>
<div class="face six">
6
</div>
</div>
</div>
CSS
#experiment {
-webkit-perspective: 1000;
color: white;
font-size: 24px;
margin-top: 100px;
}
#cube {
position: relative;
margin: 0 auto;
height: 400px;
width: 400px;
-webkit-transition: -webkit-transform 1s linear;
-webkit-transform-style: preserve-3d;
}
.face {
position: absolute;
/* background-color: rgba(50, 50, 50, 0.7); */
}
#cube .one {
width: 400px;
height: 100px;
-webkit-transform: rotateX(90deg) translateZ(50px);
background-color: #666666;
}
#cube .two {
width: 400px;
height: 400px;
-webkit-transform: translateZ(50px);
background-color: green;
}
#cube .three {
width: 100px;
height: 400px;
-webkit-transform: rotateY(90deg) translateZ(350px);
background-color: #666666;
}
#cube .four {
width: 400px;
height: 400px;
-webkit-transform: rotateY(180deg) translateZ(50px);
background-color: blue;
}
#cube .five {
width: 100px;
height: 400px;
-webkit-transform: rotateY(-90deg) translateZ(50px);
background-color: #666666;
}
#cube .six {
height: 100px;
width: 400px;
-webkit-transform: rotateX(-90deg) translateZ(350px) rotate(180deg);
background-color: #666666;
}
JavaScript
var xAngle = 4, yAngle = 4;
setInterval(function () {
xAngle += 4;
yAngle += 4;
// $('#cube').css("-webkit-transform","rotateX("+xAngle+"deg) rotateY("+yAngle+"deg)");
// $('#cube').css("-webkit-transform","rotateX("+xAngle+"deg)");
$('#cube').css("-webkit-transform","rotateY("+yAngle+"deg)");
}, 200);