示例工程 36-scroll-animations
36-scroll-animations/demo-01-progress/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; }
.panel {
position: relative;
max-width: 560px;
max-height: 240px;
margin-top: 16px;
overflow-y: auto;
border: 1px solid #e2e8f0;
border-radius: 10px;
scroll-timeline-name: --panel;
scroll-timeline-axis: block;
}
.bar {
position: sticky;
top: 0;
z-index: 2;
height: 5px;
background: #2563eb;
transform: scaleX(0);
transform-origin: 0 50%;
animation: grow linear both;
animation-timeline: --panel;
}
@keyframes grow {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
.content {
padding: 16px;
background: #ffffff;
font-size: 14px;
}
.content p {
margin: 0;
padding: 14px 0;
border-bottom: 1px solid #e2e8f0;
color: #64748b;
}
.content p:last-child { border-bottom: 0; }
@media (prefers-reduced-motion: reduce) {
.bar { animation: none; }
}