css写一个好看的加载中动画
以下是一个简单的CSS加载动画示例,使用了CSS3中的@keyframes和animation属性:
HTML代码:
<div class="loading">
<div class="loading-bar"></div>
<div class="loading-bar"></div>
<div class="loading-bar"></div>
<div class="loading-bar"></div>
<div class="loading-bar"></div>
</div>
CSS代码:
.loading {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.loading-bar {
width: 6px;
height: 30px;
margin: 0 4px;
border-radius: 2px;
animation: loading 1s ease-in-out infinite;
}
.loading-bar:nth-child(1) {
background-color: #1abc9c;
animation-delay: 0.1s;
}
.loading-bar:nth-child(2) {
background-color: #2ecc71;
animation-delay: 0.2s;
}
.loading-bar:nth-child(3) {
background-color: #3498db;
animation-delay: 0.3s;
}
.loading-bar:nth-child(4) {
background-color: #9b59b6;
animation-delay: 0.4s;
}
.loading-bar:nth-child(5) {
background-color: #e67e22;
animation-delay: 0.5s;
}
@keyframes loading {
0% {
transform: scale(1);
}
20% {
transform: scale(1, 2.5);
}
40% {
transform: scale(1);
}
}
这个加载动画由5个竖条组成,每个竖条的颜色不同,并且使用了animation-delay属性来实现不同的延迟动画效果。竖条的动画效果使用了@keyframes关键字和transform属性,通过改变竖条的高度来实现缩放效果。整个加载动画是无限循环的。
原文地址: https://www.cveoy.top/t/topic/HfB 著作权归作者所有。请勿转载和采集!