css如何制作加载
使用CSS制作加载动画
通过CSS可以创建多种加载动画效果,以下是几种常见的方法:
纯CSS旋转动画
通过@keyframes和transform属性实现旋转效果:
.loader {
width: 50px;
height: 50px;
border: 5px solid #f3f3f3;
border-top: 5px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
点状加载动画

使用多个圆点通过动画产生序列效果:
.dot-loader {
display: flex;
justify-content: center;
}
.dot-loader div {
width: 10px;
height: 10px;
margin: 0 5px;
background-color: #3498db;
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out;
}
.dot-loader div:nth-child(2) {
animation-delay: 0.2s;
}
.dot-loader div:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-15px); }
}
进度条加载动画

创建水平进度条动画:
.progress-loader {
width: 100%;
height: 5px;
background-color: #f3f3f3;
position: relative;
overflow: hidden;
}
.progress-loader::before {
content: '';
position: absolute;
left: -50%;
width: 50%;
height: 100%;
background-color: #3498db;
animation: progress 2s linear infinite;
}
@keyframes progress {
0% { left: -50%; }
100% { left: 100%; }
}
骨架屏加载效果
为内容加载前创建占位效果:
.skeleton {
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
这些方法可以根据实际需求进行调整,修改颜色、尺寸和动画时间等参数来适配不同场景。通过组合不同的CSS属性和动画效果,可以创建出丰富多样的加载动画。






