css3动画实现吃豆豆效果
实现效果:
HTML
<div class="box">
<span></span>
</div>
CSS
// 外侧边框
.box {
display: flex;
align-items: center;
margin: 100px auto;
width: 500px;
height: 120px;
border: 1px solid #ccc;
// 豆豆
span {
display: flex;
position: relative;
width: 100px;
height: 100px;
border-radius: 50%;
background-color: orange;
animation: 4s go linear infinite;
// 大嘴
&::before {
content: '';
border: 50px solid transparent;
border-right-color: #fff;
animation: 1s eat linear infinite;
}
// 眼睛
&::after {
position: absolute;
content: '';
width: 20px;
height: 20px;
left: 30px;
top: 20px;
border-radius: 50%;
background-color: #fff;
}
// 豆豆的运动
@keyframes go {
0% {
transform: translateX(0);
}
50% {
transform: translateX(400px) rotate(0);
}
51% {
transform: translateX(400px) rotateY(180deg) ;
}
100% {
transform: translateX(0) rotateY(180deg);
}
}
// 豆豆吃东西
@keyframes eat {
0% {
transform: rotateX(90deg);
}
100% {
transform: rotateX(800deg);
}
}
}
}