用CSS如何loading吃豆人的效果,方法是什么?
Admin 2022-02-23 群英技术资讯 1556 次浏览
这篇文章给大家分享一个loading动画示例,是一个吃豆人的效果。小编觉得挺有趣的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
HTML布局
<div class="container">
<div class="loading">
<div class="eat"></div>
<div class="load"></div>
<div class="load"></div>
<div class="load"></div>
</div>
</div>
CSS 样式
主要使用了动画效果,通过不断控制元素的角度位置实现一个类似于吃豆人一样的loading demo。
body {
margin: 0;
padding: 0;
background: #fff;
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loading {
position: relative;
width: 200px;
height: 50px;
display: flex;
}
.eat {
position: relative;
width: 50px;
height: 50px;
left: 0;
color: #ff0000;
animation: eat-animate 2.4s ease-in-out infinite;
}
@keyframes eat-animate {
100% {
left: 150px;
}
}
.eat::before {
content: '';
position: absolute;
width: 0;
height: 0;
width: 50px;
height: 25px;
top: 0;
border-radius: 50px 50px 0 0;
background: currentColor;
transform: rotate(-30deg);
animation: eat-top 2.4s ease-in-out infinite;
}
@keyframes eat-top {
20% {
transform: rotate(-30deg);
}
35% {
transform: rotate(0deg);
}
45% {
transform: rotate(-30deg);
}
60% {
transform: rotate(0deg);
}
70% {
transform: rotate(-30deg);
}
85% {
transform: rotate(0deg);
}
100% {
transform: rotate(0deg);
}
}
.eat::after {
content: '';
position: absolute;
width: 0;
height: 0;
width: 50px;
height: 25px;
bottom: 0;
border-radius: 0 0 50px 50px;
background: currentColor;
transform: rotate(30deg);
animation: eat-bottom 2.4s ease-in-out infinite;
}
@keyframes eat-bottom {
20% {
transform: rotate(30deg);
}
35% {
transform: rotate(0deg);
}
45% {
transform: rotate(30deg);
}
60% {
transform: rotate(0deg);
}
70% {
transform: rotate(30deg);
}
85% {
transform: rotate(0deg);
}
100% {
transform: rotate(0deg);
}
}
.load {
position: relative;
width:30px;
height: 30px;
margin: 10px;
color: #e47272;
border-radius: 50%;
background: currentColor;
}
.load:nth-child(2) {
animation: load1 2.4s linear infinite;
transform: scale(1);
}
@keyframes load1 {
35% {
transform: scale(0);
}
100% {
transform: scale(0);
}
}
.load:nth-child(3) {
animation: load2 2.4s linear infinite;
transform: scale(1);
}
@keyframes load2 {
30% {
transform: scale(1);
}
58% {
transform: scale(0);
}
100% {
transform: scale(0);
}
}
.load:nth-child(4) {
animation: load3 2.4s linear infinite;
transform: scale(1);
}
@keyframes load3 {
60% {
transform: scale(1);
}
80% {
transform: scale(0);
}
100% {
transform: scale(0);
}
}
Preview

以上就是CSS实现loading吃豆人效果的方法介绍啦,上述示例有一定的参考价值,需要的朋友可以了解看看,希望大家阅读完这篇文章能有所收获。最后,想要了解更多loading动画的实现,大家可以关注群英网络其它相关文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
HTML知识点概括前端三件套分别是HTML3,CSS5,JavaScript稍微介绍一下W3C标准:结构化标准语言(HTML)表现标准语言(CSS)行为标准(DOM,JavaScript)HTML是超文本标记语言,负责网页最基本信息的构造HTML的优势:市场需求量跨平台使用浏览器...
html实现可输入下拉菜单,不可思议是不是, 本例通过一些方法实现这个不可能的事情,感兴趣的朋友可以参考下html实现可输入下拉菜单的方法。
我们在制作HTML页面时,经常会遇到浮动问题,如果当子元素浮动时,不清除浮动就会导致后面的元素排版乱序。那么都有什么方法能够清除浮动呢?
CSS3如何实现倒计时效果?一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
在css中,可以利用“text-shadow”属性给字体设置阴影,该属性用于给文本设置阴影效果,属性值可以设置文本的水平垂直阴影、模糊距离和阴影颜色,语法为“元素{text-shadow:水平阴影 垂直阴影 blur color;}”。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008