完全不用js也能写出很好看的css动画
- 重点用到的就是**@keyframes和animation**这两个让他们动起来
- 盒子阴影box-shadow: 300px 0px 0px -80px white,
300px:左右移动 0px:上下移动 0px:阴影范围 -80px:阴影大小 white:颜色
动图截图–图片
整体代码如下
以下是用到的VsCode软件,个人觉得比HBuilder好用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我要吃豆豆</title>
<style>
body{
background-color: black;
}
.box{
position: relative;
width: 200px;
height: 200px;
margin-top: 100px;
margin-left: 100px;
box-shadow: 300px 0px 0px -80px white,
450px 0px 0px -80px white,
600px 0px 0px -80px white,
750px 0px 0px -80px white,
900px 0px 0px -80px white;
border-radius: 50%;
animation: go 1s infinite linear;
}
@keyframes go{
0%{box-shadow: 300px 0px 0px -80px white,
450px 0px 0px -80px white,
600px 0px 0px -80px white,
750px 0px 0px -80px white,
900px 0px 0px -80px white;
}
100%{box-shadow: 150px 0px 0px -80px white,
300px 0px 0px -80px white,
450px 0px 0px -80px white,
600px 0px 0px -80px white,
750px 0px 0px -80px white;
}
}
.box .top{
width: 200px;
height: 100px;
background-color: blue;
border-radius: 110px 110px 0 0;
margin-left: 100px;
animation: go1 1s infinite;
}
.box .bop{
width: 200px;
height: 100px;
background-color: blue;
border-radius: 0 0 110px 110px;
margin-left: 100px;
animation: go2 1s infinite;
}
.box .eye{
position: absolute;
top: 30px;
left: 180px;
width: 30px;
height: 30px;
background-color: black;
border-radius: 50%;
}
@keyframes go1{
0%{transform: rotate(0deg);}
50%{transform: rotate(-30deg);}
100%{transform: rotate(0deg);}
}
@keyframes go2{
0%{transform: rotate(0deg);}
50%{transform: rotate(30deg);}
100%{transform: rotate(0deg);}
}
</style>
</head>
<body>
<div class="box">
<div class="top"></div>
<div class="eye"></div>
<div class="bop"></div>
</div>
</body>
</html>