JSFiddle - React, Tailwind, and code Playground
HTML
<section class="container">
<div id="box" class="show-front">
<figure class="front">1</figure>
<figure class="back">2</figure>
<figure class="right">3</figure>
<figure class="left">4</figure>
<figure class="top">5</figure>
<figure class="bottom">6</figure>
</div>
</section>
<section id="options">
<p>
<button id="up">Up</button>
<br/><br/>
<button id="left">Left</button>
<button id="right">Right</button>
<br/><br/>
<button id="down">Down</button>
</p>
</section>
CSS
.container {
width: 150px;
height: 100px;
position: relative;
margin: 25px auto 25px auto;
perspective: 600px;
}
#box {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
}
#box figure {
display: block;
position: absolute;
border: 1px solid black;
line-height: 98px;
font-size: 45px;
text-align: center;
font-weight: bold;
color: white;
}
figure {
margin: 0;
}
#box .front,
#box .back {
width: 148px;
height: 98px;
}
#box .right,
#box .left {
width: 48px;
height: 98px;
left: 50px;
}
#box .top,
#box .bottom {
width: 148px;
height: 48px;
top: 25px;
line-height: 48px;
}
#box .front {
background: hsla(000, 100%, 50%, 0.7);
}
#box .back {
background: hsla(160, 100%, 50%, 0.7);
}
#box .right {
background: hsla(120, 100%, 50%, 0.7);
}
#box .left {
background: hsla(180, 100%, 50%, 0.7);
}
#box .top {
background: hsla(240, 100%, 50%, 0.7);
}
#box .bottom {
background: hsla(300, 100%, 50%, 0.7);
}
#box .front {
transform: translateZ(25px);
}
#box .back {
transform: rotateX(180deg) translateZ(25px);
}
#box .right {
transform: rotateY(90deg) translateZ(75px);
}
#box .left {
transform: rotateY(-90deg) translateZ(75px);
}
#box .top {
transform: rotateX(90deg) translateZ(50px);
}
#box .bottom {
transform: rotateX(-90deg) translateZ(50px);
}
#box.show-front {
transform: translateZ(-50px);
}
#box.show-front-2 {
transform: translateZ(-50px) rotateZ(90deg);
}
#box.show-front-3 {
transform: translateZ(-50px) rotateZ(180deg);
}
#box.show-front-4 {
transform: translateZ(-50px) rotateZ(270deg);
}
#box.show-back {
transform: translateZ(-50px) rotateX(180deg);
}
#box.show-back-2 {
transform: translateZ(-50px) rotateX(180deg) rotateZ(-90deg);
}
#box.show-back-3 {
transform: translateZ(-50px) rotateX(180deg)...
JavaScript
$('document').ready(function() {
var position = 'show-front';
$('#up').bind('click', function() {
if (position == 'show-front') {
$('#box').removeClass().addClass('show-bottom');
position = 'show-bottom';
} else if (position == 'show-bottom') {
$('#box').removeClass().addClass('show-back');
position = 'show-back';
} else if (position == 'show-back') {
$('#box').removeClass().addClass('show-top');
position = 'show-top';
} else if (position == 'show-top') {
$('#box').removeClass().addClass('show-front');
position = 'show-front';
//
} else if (position == 'show-front-2') {
$('#box').removeClass().addClass('show-right-2');
position = 'show-right-2';
} else if (position == 'show-right-2') {
if ($('#box').hasClass(position)) {
$('#box').removeClass().addClass('show-back-5');
} else {
$('#box').removeClass().addClass('show-back-4');
}
position = 'show-back-4';
} else if (position == 'show-back-4') {
$('#box').removeClass().addClass('show-left-2');
position = 'show-left-2';
} else if (position == 'show-left-2') {
$('#box').removeClass().addClass('show-front-2');
position = 'show-front-2';
//
} else if (position == 'show-front-3') {
$('#box').removeClass().addClass('show-top-3');
position = 'show-top-3';
} else if (position == 'show-top-3') {
$('#box').removeClass().addClass('show-back-3');
position = 'show-back-3';
} else if (position == 'show-back-3') {
$('#box').removeClass().addClass('show-bottom-3');
position = 'show-bottom-3';
} else if (position == 'show-bottom-3') {
...