css loading制作
CSS Loading动画制作方法
使用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); }
}
点状加载动画 使用多个点元素的延迟动画:

.loader-dots {
display: flex;
justify-content: center;
gap: 8px;
}
.dot {
width: 10px;
height: 10px;
background-color: #333;
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out;
}
.dot:nth-child(2) {
animation-delay: 0.2s;
}
.dot:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
进度条加载动画 线性进度条效果:
.progress-loader {
width: 100%;
height: 4px;
background-color: #e0e0e0;
position: relative;
overflow: hidden;
}
.progress-loader::before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 50%;
background: #4285f4;
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; }
}
优化技巧
- 使用
will-change属性提升动画性能:will-change: transform; - 考虑使用
prefers-reduced-motion媒体查询为运动敏感用户提供替代方案 - 保持加载动画简洁,避免过度复杂影响性能
- 通过
opacity和visibility控制加载元素的显示/隐藏过渡效果
这些方法可以单独使用或组合创建更复杂的加载效果,根据实际需求调整尺寸、颜色和动画时间等参数。






