我想旋转立方体,并扩展其面。我已经尝试过类似以下的内容,
.wrapper{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.cube-wrap {
width: 40px;
height: 40px;
-webkit-perspective: 2000px;
-webkit-perspective-origin: 50% -500px;
}
.single-box {
background-size: cover;
display: block;
position: absolute;
width: 40px;
height: 40px;
background-color: #60c2ef;
-webkit-transform: rotateY(45deg) translateZ(-200px) rotateX(15deg);
-webkit-transform-origin: 50% 50% 0;
}
.box {
-webkit-transform-style: preserve-3d;
-webkit-animation: rotate 1.5s infinite ease;
}
.side-front {
animation: side-front-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(0deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: translateZ(20px);
}
.side-back {
animation: side-back-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-180deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
border: #ffffff;
-webkit-transform: rotateY(180deg) translateZ(20px);
}
.side-top {
animation: side-top-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(90deg) translateZ(20px);
}
.side-bottom {
animation: side-bottom-animation 3s ease infinite;
animation-delay: 0;
transform: rotateX(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateX(-90deg) translateZ(20px);
}
.side-left {
animation: side-left-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(-90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(-90deg) translateZ(20px);
}
.side-right {
animation: side-right-animation 3s ease infinite;
animation-delay: 100ms;
transform: rotateY(90deg) translateZ(150px);
animation-fill-mode: forwards;
transform-origin: 50% 50%;
background-color: #007dc5;
-webkit-transform: rotateY(90deg) translateZ(20px);
}
@-webkit-keyframes rotate {
0% { -webkit-transform: rotateY(0); }
100% { -webkit-transform: rotateY(360deg); }
}
@-webkit-keyframes side-top-animation {
0% { opacity: 1; transform: rotateX(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(90deg) translateZ(150px) }
}
@-webkit-keyframes side-bottom-animation {
0% { opacity: 1; transform: rotateX(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateX(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateX(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateX(-90deg) translateZ(150px) }
}
@-webkit-keyframes side-front-animation {
0% { opacity: 1; transform: rotateY(0deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(0deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(0deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(0deg) translateZ(150px) }
}
@-webkit-keyframes side-back-animation {
0% { opacity: 1; transform: rotateY(-180deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-180deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-180deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-180deg) translateZ(150px) }
}
@-webkit-keyframes side-left-animation {
0% { opacity: 1; transform: rotateY(-90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(-90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(-90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(-90deg) translateZ(150px) }
}
@-webkit-keyframes side-right-animation {
0% { opacity: 1; transform: rotateY(90deg) translateZ(150px)}
20% { opacity: 1; transform: rotateY(90deg) translateZ(75px)}
70% { opacity: 1; transform: rotateY(90deg) translateZ(75px) }
90% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
100% { opacity: 1; transform: rotateY(90deg) translateZ(150px) }
}
<div class="wrapper">
<div class="cube-wrap">
<div class="box">
<div class="single-box side-back"></div>
<div class="single-box side-top"></div>
<div class="single-box side-bottom"></div>
<div class="single-box side-left"></div>
<div class="single-box side-right"></div>
<div class="single-box side-front"></div>
</div>
</div>
</div>
上面的代码有效。它旋转和旋转,但面距离不够近,无法看起来像立方体。我该怎么解决。
有人可以帮我这个忙吗?谢谢。
我不知道如何将动画添加到立方体面。并且多维数据集应如下图所示。
答案 0 :(得分:0)
在您的代码中,将height
的{{1}}和width
更改为.single-box
,以匹配一个框,然后补偿动画中的更改,同时更改{{ 150px
的1}}和height
设为width
的相同值。
所以你会得到类似的东西
.cube-wrap
.single-box