CSS3 & Modern Layouts (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
CSS Scroll-Driven Animations (`animation-timeline: scroll()`).
senior LevelCode ExampleSystem Design
In Simple Words: Animates properties proportionally linked to the scroll position of a container with zero JavaScript:
css
@keyframes progressBar {
from { transform: scaleX(0); }
to { transform: scaleX(1); }
}
.scroll-progress-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 4px;
background: royalblue;
transform-origin: left;
/* Links animation progress directly to document scroll! */
animation: progressBar linear;
animation-timeline: scroll();
}
Runs entirely on the compositor thread at 120 FPS, even when JavaScript main thread is blocked!