css3动画实现3d旋转效果
程序员文章站
2022-03-19 17:41:22
...
这个项目我只用了css3中的animation和transition配合使用,主要是把六个面全部根据旋转角度与偏移实现的。
下面直接上代码。
<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: flex;
justify-content: center;
align-self: center;
background: radial-gradient(#fff, rgb(5, 1, 35));
animation: bj 12s infinite;
}
@keyframes bj {
0% {
background-image: url(./images/timg2.jpg);
}
20% {
background-image: url(./images/timg1.jpg);
}
40% {
background-image: url(./images/timg8.jpg);
}
60% {
background-image: url(./images/timg5.jpg);
}
80% {
background-image: url(./images/timg7.jpg);
}
100% {
background-image: url(./images/timg6.jpg);
}
}
.container {
width: 400px;
height: 400px;
margin-top: 250px;
position: relative;
transform-style: preserve-3d;
/* transform: rotateX(-20deg) rotateY(-20deg); */
animation: hd 12s infinite;
}
.container .item {
position: absolute;
width: 100%;
height: 100%;
opacity: 0.8;
}
.container .front {
transform: translateZ(200px);
}
.container .back {
transform: rotateY(180deg) translateZ(200px);
}
.container .left {
transform: rotateY(-90deg) translateZ(200px);
}
.container .right {
transform: rotateY(90deg) translateZ(200px);
}
.container .top {
transform: rotateX(90deg) translateZ(200px);
}
.container .bottom {
transform: rotateX(-90deg) translateZ(200px);
}
@keyframes hd {
0% {
transform: rotateY(90deg);
}
20% {
transform: rotateY(180deg);
}
40% {
transform: rotateY(270deg);
}
60% {
transform: rotateX(-90deg);
}
80% {
transform: rotateX(0);
}
100% {
transform: rotateX(90deg);
}
}
h1{
color: pink;
text-align: center;
margin-top: -200px;
}
</style>
</head>
<body>
<div class="container">
<div class="item front">
<img src="./images/timg7.jpg" width="100%" height="100%" alt="">
<h1>猪</h1>
</div>
<div class="item back">
<img src="./images/timg1.jpg" width="100%" height="100%" alt="">
<h1>猪</h1>
</div>
<div class="item left">
<img src="./images/timg2.jpg" width="100%" height="100%" alt="">
<h1>我</h1>
</div>
<div class="item right">
<img src="./images/timg8.jpg" width="100%" height="100%" alt="">
<h1>欢</h1>
</div>
<div class="item top">
<img src="./images/timg5.jpg" width="100%" height="100%" alt="">
<h1>你</h1>
</div>
<div class="item bottom ">
<img src="./images/timg6.jpg" width="100%" height="100%" alt="">
<h1>猪</h1>
</div>
</div>
</body>
</html>
大家记得换一下图片尽量大一些比较好
上一篇: 探寻微博营销十年不衰的秘密:微博引流技巧
下一篇: 618初战 京东+拼多多为何小于淘宝