<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>立方体</title>
</head>
<style>
*{
padding: 0px;
margin: 0px;
}
body{
background-repeat: no-repeat;
background-size:cover;
overflow: hidden;
background-position:top;
}
.box{
width: 400px;
height: 400px;
/* background-color: black; */
margin: 300px auto;
animation: 20s rotate linear;
transform-style:preserve-3d;
animation-iteration-count:infinite;
}
@keyframes rotate{
from{
transform:rotateX(10deg) rotateY(10deg) rotateZ(10deg)
}
to{
transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
}
}
.box:hover{
animation-play-state:paused ;
}
.box div{
width: 400px;
height: 400px;
position: absolute;
transition: 1s all ease-in-out ;
}
img{
width: 400px;
height: 400px;
}
.box:hover img {
border-radius: 10%;
}
.box :nth-child(1){
transform: translateZ(-200px) ;
}
.box :nth-child(2){
transform: translateZ(200px);
}
.box :nth-child(3){
transform: translateX(200px) rotateY(90deg);
}
.box :nth-child(4){
transform: translateX(-200px) rotateY(-90deg);
}
.box :nth-child(5){
transform: translateY(-200px) rotateX(90deg);
}
.box :nth-child(6){
transform: translateY(200px) rotateX(-90deg);
}
.box:hover :nth-child(1){
transform: translateZ(-300px) ;
}
.box:hover :nth-child(2){
transform: translateZ(300px);
}
.box:hover :nth-child(3){
transform: translateX(300px) rotateY(90deg);
}
.box:hover :nth-child(4){
transform: translateX(-300px) rotateY(-90deg);
}
.box:hover :nth-child(5){
transform: translateY(-300px) rotateX(90deg);
}
.box:hover :nth-child(6){
transform: translateY(300px) rotateX(-90deg);
}
</style>
<body background="./tu/rng.jpg">
<div class="box">
<div><img src="./tu/rng1.jpg" alt=""></div>
<div><img src="./tu/rng2.jpg" alt=""></div>
<div><img src="./tu/rng3.jpg" alt=""></div>
<div><img src="./tu/rng4.jpg" alt=""></div>
<div><img src="./tu/rng5.jpg" alt=""></div>
<div><img src="./tu/rng6.jpg" alt=""></div>
</div>
</body>
</html>
利用动画和旋转实现3D立方体的运动和设计