SnippetUI

进度条加载动画

这是设备组的一项补充,CSS 的实际使用导致了三种类型的渐进运动:波浪变化和连续流动。

HTMLCSS

预览

3 种进度条动画。不需要 JavaScript,纯 CSS 实现。

渐变+微光
条纹条
脉冲棒

用例和功能

  • 文件上传进度显示:可以用作假栏,用CSS动画来表达进度。
  • 3种动画图案:您可以根据每个主题进行选择。
  • 纯CSS实现:不需要框架。只需“@keyframes”即可完成。
  • 高度可自由调整:只需更改.pb-trackheight即可。

设计和用户体验要点

  1. 渐变条:通过background-size: 200%background-position动画实现闪烁效果。
  2. 条纹条:具有“重复线性渐变”和“背景位置”动画的流动条纹的表示。
  3. 脉冲条:在高负载处理过程中出现的带有间歇性“不透明度”的移动条。

如何定制

更改高度:

.pb-track { height: 12px; } /* 厚 */
.pb-track { height: 4px; }  /* 薄 */

更改渐变色:

.pb-gradient .pb-fill {
  background: linear-gradient(90deg, #06b6d4, #3b82f6, #8b5cf6);
}

实现代码

<div class="pb-preview-bg">
<div class="pb-item">
  <div class="pb-label">渐变+微光</div>
  <div class="pb-track"><div class="pb-fill pb-gradient-fill"></div></div>
</div>
<div class="pb-item">
  <div class="pb-label">条纹条</div>
  <div class="pb-track"><div class="pb-fill pb-striped-fill"></div></div>
</div>
<div class="pb-item">
  <div class="pb-label">脉冲棒</div>
  <div class="pb-track"><div class="pb-fill pb-pulse-fill"></div></div>
</div>
</div>

<style>
`
.pb-preview-bg {
width: 100%;
max-width: 400px;
display: flex;
flex-direction: column;
gap: 2rem;
}
.pb-item {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.pb-label {
color: #fff;
font-size: 0.9rem;
font-family: sans-serif;
}
.pb-track {
width: 100%;
height: 8px;
background: rgba(255,255,255,0.1);
border-radius: 999px;
overflow: hidden;
}
.pb-fill {
height: 100%;
border-radius: 999px;
width: 0%;
}
.pb-gradient-fill {
background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
background-size: 200% 100%;
animation: pb-slide 2s ease infinite, pb-shimmer 2s linear infinite;
}
.pb-striped-fill {
background-color: #3b82f6;
background-image: repeating-linear-gradient(
  45deg,
  rgba(255, 255, 255, 0.15) 0px,
  rgba(255, 255, 255, 0.15) 10px,
  transparent 10px,
  transparent 20px
);
background-size: 28px 28px;
animation: pb-slide 2.5s ease infinite, pb-stripe 1s linear infinite;
}
.pb-pulse-fill {
background: #10b981;
animation: pb-slide 3s ease infinite, pb-pulse 1.5s ease-in-out infinite alternate;
}
@keyframes pb-slide {
0% { width: 0%; }
80%, 100% { width: 100%; }
}
@keyframes pb-shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
@keyframes pb-stripe {
0% { background-position: 0 0; }
100% { background-position: 28px 0; }
}
@keyframes pb-pulse {
0% { opacity: 0.6; }
100% { opacity: 1; box-shadow: 0 0 8px 2px rgba(16, 185, 129, 0.5); }
}
`
</style>

浏览器兼容性状态

浏览器兼容性状态
Chrome 43+✅ 完全兼容
火狐 16+✅ 完全兼容
Safari 9+✅ 完全兼容
边缘 79+✅ 完全兼容