css屬性
- animation 關鍵幀
- opacity 透明度
- transform 動畫
- transform-style: preserve-3d; /* 重點:保留子元素的3d效果*/
- perspective: 1000px; /*設置透視點*/
code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
perspective: 1000px;
}
.img-box{
width: 300px;
height: 300px;
margin: 100px auto;
transform-style: preserve-3d;
animation-name: donghua;
animation-duration: 5s;
animation-iteration-count: infinite;
}
@keyframes donghua{
from {
transform: rotate3d(0,0,0, 0deg);
}
to {
transform: rotate3d(1,1,1, 720deg);
}
}
.front{
background-image: url(img/img1.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
opacity: 0.3;
transform: translateZ(140px);
position: absolute;
}
.back{
background-image: url(img/img2.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
position: absolute;
opacity: 0.3;
transform: translateZ(-145px);
}
.left{
background-image: url(img/img3.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
position: absolute;
opacity: 0.3;
transform: rotateY(-90deg) translateZ(148px);
}
.right{
background-image: url(img/img4.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
position: absolute;
opacity: 0.3;
transform: rotateY(90deg) translateZ(148px);
}
.top{
background-image: url(img/img5.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
position: absolute;
opacity: 0.3;
transform: rotateX(-90deg) translateZ(-150px);
}
.bottom{
background-image: url(img/img6.jpg);
background-size: 100% 100%;
height: inherit;
width: inherit;
position: absolute;
opacity: 0.3;
transform: rotateX(90deg) translateZ(-150px);
}
</style>
</head>
<body>
<div class="img-box">
<div class="front"></div>
<div class="back"></div>
<div class="left"></div>
<div class="right"></div>
<div class="top"></div>
<div class="bottom"></div>
</div>
</body>
</html>
效果