html代码
<div class="max">
<div class="A">
<div class="a">
<img src="food1.jpg" alt="">
<img src="food2.jpg" alt="">
<img src="food3.jpg" alt="">
<img src="food4.jpg" alt="">
<img src="food5.jpg" alt="">
<img src="food6.jpg" alt="">
</div>
<div class="b">
<img src="food7.jpg" alt="">
<img src="food8.jpg" alt="">
<img src="food9.jpg" alt="">
<img src="food10.jpg" alt="">
<img src="food11.jpg" alt="">
<img src="food12.jpg" alt="">
</div>
</div>
</div>
CSS代码
body{
height: 920px;
margin: 0;
padding: 0;
perspective: 4000px;
transform-style: preserve-3d;
background: url(background.jpg) no-repeat 0px 0px/100% 100%;
}
.max{
width: 100%;
height: 920px;
background: rgba(255,255,255,0.3);
}
.A{
width: 300px;
height: 300px;
position: absolute;
left: 35%;
top: 25%;
transform: rotateY(0deg);
animation: f 8s linear infinite;
transform-style: preserve-3d;
}
@keyframes f {
0%{
transform:rotateY(0deg) rotateX(0deg);
}
100%{
transform:rotateY(360deg) rotateX(360deg);
}
}
.A .a{
width: 200px;
height: 200px;
transform-style: preserve-3d;
position: absolute;
top: 50px;
left: 50px;
}
.A .b{
width: 400px;
height: 400px;
transform-style: preserve-3d;
position: absolute;
}
.a img{
width: 200px;
height: 200px;
position: absolute;
}
.b img{
width: 300px;
height: 300px;
opacity: 0.7;
position: absolute;
}
.a img:nth-child(1){
transform: rotateY(90deg) translateZ(100px);
}
.a img:nth-child(2){
transform: rotateY(180deg) translateZ(100px);
}
.a img:nth-child(3){
transform: rotateY(270deg) translateZ(100px);
}
.a img:nth-child(4){
transform: rotateY(360deg) translateZ(100px);
}
.a img:nth-child(5){
transform: rotateX(90deg) translateZ(100px);
}
.a img:nth-child(6){
transform: rotateX(270deg) translateZ(100px);
}
.b img:nth-child(1){
transform: rotateY(90deg) translateZ(150px);
transition: 2s;
}
.b img:nth-child(2){
transform: rotateY(180deg) translateZ(150px);
transition: 1s;
}
.b img:nth-child(3){
transform: rotateY(270deg) translateZ(150px);
transition: 1s;
}
.b img:nth-child(4){
transform: rotateY(360deg) translateZ(150px);
transition: 1s;
}
.b img:nth-child(5){
transform: rotateX(90deg) translateZ(150px);
transition: 1s;
}
.b img:nth-child(6){
transform: rotateX(270deg) translateZ(150px);
transition: 1s;
}
A:hover .b img:nth-child(1){
transform: rotateY(90deg) translateZ(350px);
}
.A:hover .b img:nth-child(2){
transform: rotateY(180deg) translateZ(350px);
}
.A:hover .b img:nth-child(3){
transform: rotateY(270deg) translateZ(350px);
}
.A:hover .b img:nth-child(4){
transform: rotateY(360deg) translateZ(350px);
}
.A:hover .b img:nth-child(5){
transform: rotateX(90deg) translateZ(350px);
}
.A:hover .b img:nth-child(6){
transform: rotateX(270deg) translateZ(350px);
}
这次主要用到了过渡、定位、2D转换、3D转换等知识
transform 属性向元素应用 2D 或 3D 转换。该属性允许我们对元素进行旋转、缩放、移动或倾斜。 transform: rotateY() 方法使元素绕其 Y 轴旋转给定角度; transform: rotateX() 方法使元素绕其 X 轴旋转给定角度; transform: translateZ() 方法使元素沿 X 轴方向平移; animation: f 8s linear infinite; transform-style: preserve-3d 规定被嵌套元素如何在3D空间中显示,这里是以3D效果显示; animation: f 8s linear infinite 动画播放时长为8s、循环播放(infinite)、以linear方式进行播放; position: absolute 绝对定位; perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。 @keyframes: 定义动画在不同阶段的状态。
效果: