示例工程 36-scroll-animations
36-scroll-animations/demo-02-reveal/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 {
display: grid;
gap: 12px;
max-width: 520px;
max-height: 300px;
margin-top: 16px;
padding: 12px;
overflow-y: auto;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #ffffff;
}
.wrap {
view-timeline-name: --card;
view-timeline-axis: block;
}
.card {
display: grid;
place-items: center;
min-height: 120px;
border-radius: 8px;
background: #2563eb;
color: #ffffff;
font-family: ui-monospace, monospace;
font-size: 18px;
}
@supports (animation-timeline: scroll()) {
.card {
opacity: 0;
transform: translateY(24px);
animation: reveal linear both;
animation-timeline: --card;
animation-range: entry 0% entry 70%;
}
}
@keyframes reveal {
from { opacity: 0; transform: translateY(24px); }
to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
.card {
animation: none;
opacity: 1;
transform: none;
}
}