I try to understand how to animate a 3d object with css. Right now i have an isometric type of shape that shows its inside when it's hovered. But additionally i want to animate this isometric shape to turn around 360deg as 3d shape infinite. I've been fiddling with its transform for each box but it doesn't work at all.
Can anyone help me and give some tips or explanations how i can achieve this?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.cube {
width: 100px;
height: 150px;
position: absolute;
background-color: red;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: 50% auto;
}
.outterstack .left {
min-width: 100px;
min-height: 250px;
transform-origin: 0 0;
transform: rotate(90deg) skewX(-30deg) scaleY(0.864);
background-color: grey;
}
.outterstack .right {
min-height: 100px;
min-width: 250px;
transform-origin: 0 0;
transform: rotate(-30deg) skewX(-30deg) scaleY(0.864);
position: relative;
bottom: 250px;
background-color: grey;
}
.outterstack .up {
width: 250px;
height: 250px;
transform-origin: 0 0;
transform: rotate(210deg) skew(-30deg) scaleY(0.864);
position: relative;
bottom: 350px;
background-color: violet;
}
.insidestack .left {
min-width: 50px;
min-height: 150px;
transform-origin: 0 0;
transform: rotate(90deg) skewX(-30deg) scaleY(0.864);
background-color: black;
}
.insidestack .right {
min-height: 100px;
min-width: 150px;
transform-origin: 0 0;
transform: rotate(-30deg) skewX(-30deg) scaleY(0.864);
position: relative;
bottom: 149px;
background-color: yellow;
}
.insidestack .up {
width: 150px;
height: 150px;
transform-origin: 0 0;
transform: rotate(210deg) skew(-30deg) scaleY(0.864);
position: relative;
bottom: 249px;
background-color: green;
}
.one,
.two,
.three,
.oneins,
.twoins,
.threeins,
.four {
position: relative;
left: 150px;
transition: 1s;
}
.one {
top: 150px;
z-index: 7;
}
.oneins {
bottom: 400px;
z-index: 1;
}
.two {
bottom: 740px;
z-index: 5;
}
.twoins {
bottom: 1200px;
z-index: 1;
}
.three {
bottom: 1630px;
z-index: 3;
}
.threeins {
bottom: 2120px;
z-index: 1;
}
.four {
bottom: 2520px;
z-index: 1;
}
.cube:hover .one {
top: 150px;
z-index: 7;
}
.cube:hover .oneins {
bottom: 400px;
z-index: 6;
}
.cube:hover .two {
bottom: 650px;
z-index: 5;
}
.cube:hover .twoins {
bottom: 1200px;
z-index: 4;
}
.cube:hover .three {
bottom: 1450px;
z-index: 3;
}
.cube:hover .threeins {
bottom: 2000px;
z-index: 2;
}
.cube:hover .four {
bottom: 2250px;
z-index: 1;
}
<div class="cube">
<div class="outterstack one">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="insidestack oneins">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="outterstack two">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="insidestack twoins">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="outterstack three">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="insidestack threeins">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
<div class="outterstack four">
<div class="left"></div>
<div class="right"></div>
<div class="up"></div>
</div>
</div>