Wavy progress track
波浪动态进度条
Glide a continuous sine-wave active fill along a Material-inspired progress track.
Also searched as: Material 波浪进度条, 起伏正弦加载条, 波浪式进度动画, Wavy Progress
- Placement
- Article, Button
- Mood
- Playful, Crisp
- Trigger
- 一直循环
- Site types
- 工具和应用, 个人网站, 品牌官网
How it works & accessibility
Tiles a periodic SVG wave mask one wavelength wider than the clamped progress fill and loops translate linearly by minus one wavelength so start and end frames match seamlessly; reduced motion halts wave travel.
Best for: Article, Button (一直循环).
Reduced motion: 停止波浪横向流动,静止呈现当前进度百分比对应的波形轨道
Mobile & touch: 波浪流动完全运行在合成层 translate 上,无布局重排与重绘负担
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 波浪周期 | duration | 1200ms | — | — |
| 单个波长 | wavelength | 24px | — | — |
Ready-to-paste AI prompt
Add “Wavy progress track” to the article in my project: Tiles a periodic SVG wave mask one wavelength wider than the clamped progress fill and loops translate linearly by minus one wavelength so start and end frames match seamlessly; reduced motion halts wave travel.
Parameters: duration: 1200ms, wavelength: 24px.
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/wavy-progress.md (canonical specification and reference code).Dependency-free reference code
CSS
.wp-track {
--wp-duration: 1200ms;
--wp-wavelength: 24px;
--wp-value: 68;
position: relative;
display: flex;
align-items: center;
gap: 8px;
height: 16px;
}
.wp-fill {
position: relative;
flex: 0 0 auto;
width: calc(var(--wp-value) * 1%);
height: 100%;
overflow: hidden;
}
.wp-wave {
position: absolute;
left: 0;
top: 0;
width: calc(100% + var(--wp-wavelength));
height: 100%;
background: currentColor;
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12' preserveAspectRatio='none'%3E%3Cpath d='M0 6 Q6 1 12 6 T24 6' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12' preserveAspectRatio='none'%3E%3Cpath d='M0 6 Q6 1 12 6 T24 6' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round'/%3E%3C/svg%3E");
-webkit-mask-size: var(--wp-wavelength) 100%;
mask-size: var(--wp-wavelength) 100%;
-webkit-mask-repeat: repeat-x;
mask-repeat: repeat-x;
animation: wp-flow var(--wp-duration) linear infinite;
}
.wp-rest {
flex: 1 1 0;
height: 4px;
border-radius: 99px;
background: currentColor;
opacity: 0.22;
}
@keyframes wp-flow {
0% {
translate: 0 0;
}
100% {
translate: calc(var(--wp-wavelength) * -1) 0;
}
}
@media (prefers-reduced-motion: reduce) {
.wp-wave {
animation: none;
}
}JavaScript
// 波浪动态进度条(Wavy progress track)· 原生 JS,不依赖任何库。
// 用法:const ctl = wavyProgress(root, { duration: 1200, wavelength: 24 });
// 返回 { setValue(percent), destroy() }。
export function wavyProgress(root, { duration = 1200, wavelength = 24 } = {}) {
if (!root) return null;
const prevDuration = root.style.getPropertyValue('--wp-duration');
const prevWavelength = root.style.getPropertyValue('--wp-wavelength');
const prevValue = root.style.getPropertyValue('--wp-value');
root.classList.add('wp-track');
root.style.setProperty('--wp-duration', `${duration}ms`);
root.style.setProperty('--wp-wavelength', `${wavelength}px`);
const setValue = (percent) => {
const clamped = Math.max(0, Math.min(100, Number(percent) || 0));
root.style.setProperty('--wp-value', String(clamped));
root.setAttribute('aria-valuenow', String(Math.round(clamped)));
};
return {
setValue,
destroy() {
if (prevDuration) root.style.setProperty('--wp-duration', prevDuration);
else root.style.removeProperty('--wp-duration');
if (prevWavelength) root.style.setProperty('--wp-wavelength', prevWavelength);
else root.style.removeProperty('--wp-wavelength');
if (prevValue) root.style.setProperty('--wp-value', prevValue);
else root.style.removeProperty('--wp-value');
},
};
}HTML
<div class="wp-track" role="progressbar" aria-label="上传进度" aria-valuemin="0" aria-valuemax="100" aria-valuenow="68">
<div class="wp-fill">
<span class="wp-wave" aria-hidden="true"></span>
</div>
<span class="wp-rest" aria-hidden="true"></span>
</div>