css3 3D动画 旋转木马(奔跑的小熊)
程序员文章站
2022-03-19 15:57:28
...
效果图
直接上代码(复制可用)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
body{
/*透视*/
perspective: 800px;
/*底色*/
background-color: #eee;
}
section{
/*绝对定位*/
position:absolute;
width: 200px;
height: 100px;
/*开启3D效果*/
transform-style: preserve-3d;
top:50%;
left:45%;
margin: 220px auto;
/*使用动画*/
animation: totate 10s linear infinite,move 0.3s steps(8) infinite;
/*过渡*/
transition: all 1s;
background: url(./bpdx.png) no-repeat;
}
div{
/*给所有的div附加背景图*/
position:absolute;
width: 100%;
height: 100%;
background: url(./bpdx.png) no-repeat;
animation: move 1s steps(8) infinite;
transition: all 1s;
}
div:nth-child(1){
transform:rotateY(0) translateZ(300px)/*Y轴依次递增旋转60度 Z轴(我们与屏幕的距离)*/
}
div:nth-child(2){
transform:rotateY(60deg) translateZ(300px)
}
div:nth-child(3){
transform:rotateY(120deg) translateZ(300px)
}
div:nth-child(4){
transform:rotateY(180deg) translateZ(300px)
}
div:nth-child(5){
transform:rotateY(240deg) translateZ(300px)
}
div:nth-child(6){
transform:rotateY(300deg) translateZ(300px)
}
/*旋转section*/
@keyframes totate {
0%{
transform: rotateY(0deg);
}
100%{
transform: rotateY(360deg);
}
}
/*小熊奔跑*/
@keyframes move {
0%{
background-position: 0;
}
100%{
background-position: -1600px;
}
}
</style>
<body>
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>
素材图(透明背景图,加底色才看的明显)
上一篇: 运用CSS3 3D转换实现案例—旋转木马
下一篇: 案例-旋转木马(CSS3)