示例工程 35-keyframes
35-keyframes/demo-02-multi/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
body {
margin: 0;
padding: 32px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, sans-serif;
line-height: 1.7;
}
h1 { margin: 0 0 8px; font-size: 26px; }
.stage {
position: relative;
width: 220px;
height: 170px;
margin-top: 18px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #ffffff;
}
.ball {
position: absolute;
top: 4px;
left: 4px;
width: 32px;
height: 32px;
border-radius: 50%;
background: #2563eb;
animation: orbit 4s ease-in-out infinite;
}
@keyframes orbit {
0% { transform: translate(0, 0); background: #2563eb; }
25% { transform: translate(180px, 0); background: #7c3aed; }
50% { transform: translate(180px, 130px); background: #db2777; }
75% { transform: translate(0, 130px); background: #f59e0b; }
100% { transform: translate(0, 0); background: #2563eb; }
}
.progress {
width: 260px;
max-width: 100%;
height: 14px;
margin-top: 20px;
overflow: hidden;
border-radius: 999px;
background: #e2e8f0;
}
.bar {
display: block;
width: 100%;
height: 100%;
background: #2563eb;
transform-origin: left center;
animation: load 6s steps(10, end) infinite;
}
@keyframes load {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
@media (prefers-reduced-motion: reduce) {
.ball { animation: none; }
.bar { animation: none; transform: scaleX(0.6); }
}