第一步
静态初始摆放
html
css
.C4 {
perspective: 1000px;
margin: 0 auto;
width: 50%;
height: 300px;
background-color: #0a0400;
}
.C4>section div {
width: 300px;
height: 200px;
position: absolute;
top: 0;
left: 0;
}
/* 最内部样式 */
.C4 section div:nth-child(1) {
background: url(imege/动画1.jpg);
background-size: 300px 200px;
transform: translateZ(150px);
}
.C4 section div:nth-child(3) {
background: url(imege/动画2.jpg.webp);
background-size: 300px 200px;
transform: rotateY(90deg) translateZ(150px);
}
.C4 section div:nth-child(5) {
background: url(imege/动画3.jpg.webp);
background-size: 300px 200px;
transform: rotateY(180deg) translateZ(150px);
}
.C4 section div:nth-child(7) {
background: url(imege/动画4.jpg);
background-size: 300px 200px;
transform: rotateY(-90deg) translateZ(150px);
}
.C4 section div:nth-child(9) {
background: url(imege/动画5.jpg.webp);
background-size: 300px 200px;
transform: rotateX(90deg) translateZ(130px);
}
.C4 section div:nth-child(11) {
background: url(imege/动画6.jpg);
background-size: 300px 200px;
transform: rotateX(-90deg) translateZ(130px);
}
/* 外部样式 */
.C4 section div:nth-child(2) {
background-color: rgba(88, 43, 234, 0.5);
width: 350px;
height: 240px;
transform: translateZ(200px);
transition: all 3s;
}
.C4 section div:nth-child(4) {
width: 350px;
height: 240px;
transform: rotateY(90deg) translateZ(200px);
background-color: rgba(6, 237, 237, 0.5);
}
.C4 section div:nth-child(6) {
background-color: rgba(180, 28, 28, 0.5);
width: 350px;
height: 240px;
transform: rotateY(180deg) translateZ(200px);
}
.C4 section div:nth-child(8) {
background-color: rgba(178, 184, 26, 0.5);
width: 350px;
height: 240px;
transform: rotateY(-90deg) translateZ(200px);
}
.C4 section div:nth-child(10) {
background-color: rgba(175, 59, 186, 0.5);
width: 350px;
height: 240px;
transform: rotateX(90deg) translateZ(200px);
}
.C4 section div:nth-child(12) {
background-color: rgba(71, 234, 46, 0.5);
width: 350px;
height: 240px;
transform: rotateX(-90deg) translateZ(200px);
}
第二步
动态
在以上基础只改变了css
.C4>section {
width: 300px;
height: 200px;
position: relative;
margin: 300px auto;
transform-style: preserve-3d;
transform: rotateX(60deg);
animation: mofang 10s linear infinite;
}
@keyframes mofang {
0% {
transform: rotateX(0) rotateY(0) rotateZ(0);
}
100% {
transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
}
}
第三步
触发特效
同上只改变css
/* 悬浮特效 */
.C4:hover {
background-color: pink;
}
.C4:hover section>div:nth-child(2) {
transition-duration: 1s;
transform: translateZ(600px);
}
.C4:hover section>div:nth-child(4) {
transition-duration: 1s;
transform: rotateY(90deg) translateZ(600px);
}
.C4:hover section>div:nth-child(6) {
transition-duration: 1s;
transform: rotateY(180deg) translateZ(600px);
}
.C4:hover section>div:nth-child(8) {
transition-duration: 1s;
transform: rotateY(-90deg) translateZ(600px);
}
.C4:hover section>div:nth-child(10) {
transition-duration: 1s;
transform: rotateX(90deg) translateZ(600px);
}
.C4:hover section>div:nth-child(12) {
transition-duration: 1s;
transform: rotateX(-90deg) translateZ(600px);
}