一、实现效果
二、代码示例
<!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>Document</title>
<style>
body{
perspective: 800px;
}
img{
width: 300px;
height: 300px;
}
.cube{
/* 设置3d变形效果 */
transform-style: preserve-3d;
width: 300px;
height: 300px;
/* background-color: aquamarine; */
margin: 200px auto;
transition: 3s;
}
.cube div{
width: 300px;
height: 300px;
position: absolute;
opacity: 0.9;
transition: 3s;
}
.box1{
transform: rotateY(90deg) translateZ(150px);
}
.box2{
transform: rotateY(-90deg) translateZ(150px);
}
.box3{
transform: rotateX(90deg) translateZ(150px);
}
.box4{
transform: rotateX(-90deg) translateZ(150px);
}
.box5{
transform: rotateY(0deg) translateZ(150px);
}
.box6{
transform: rotateY(180deg) translateZ(150px);
}
.cube:hover{
animation: test 3s linear;
}
.cube:hover .box1{
animation: box1 3s linear;
transition: 3s;
}
.cube:hover .box2{
animation: box2 3s linear;
transition: 3s;
}
.cube:hover .box3{
animation: box3 3s linear;
transition: 3s;
}
.cube:hover .box4{
animation: box4 3s linear;
transition: 3s;
}
.cube:hover .box5{
animation: box5 3s linear;
transition: 3s;
}
.cube:hover .box6{
animation: box6 3s linear;
transition: 3s;
}
@keyframes box1 {
from{
transform: rotateY(90deg) translateZ(150px)
}
to{
transform: rotateY(90deg) translateZ(280px);
}
}
@keyframes box2 {
from{
transform: rotateY(-90deg) translateZ(150px)
}
to{
transform: rotateY(-90deg) translateZ(280px);
}
}
@keyframes box3 {
from{
transform: rotateX(90deg) translateZ(150px)
}
to{
transform: rotateX(90deg) translateZ(280px);
}
}
@keyframes box4 {
from{
transform: rotateX(-90deg) translateZ(150px)
}
to{
transform: rotateX(-90deg) translateZ(280px);
}
}
@keyframes box5 {
from{
transform: rotateY(0deg) translateZ(150px)
}
to{
transform: rotateY(0deg) translateZ(280px);
}
}
@keyframes box6 {
from{
transform: rotateY(180deg) translateZ(150px)
}
to{
transform: rotateY(180deg) translateZ(280px);
}
}
@keyframes test {
from{
transform: rotateX(0) rotateY(0);
}
to{
transform: rotateX(360deg) rotateY(360deg);
}
}
</style>
</head>
<body>
<div class="cube">
<div class="box1">
<img src="./images/m1.jpg">
</div>
<div class="box2">
<img src="./images/m2.jpg">
</div>
<div class="box3">
<img src="./images/m3.jpg">
</div>
<div class="box4">
<img src="./images/m4.jpg">
</div>
<div class="box5">
<img src="./images/m5.jpg">
</div>
<div class="box6">
<img src="./images/m6.jpg">
</div>
</div>
</body>
</html>