Scroll-Driven CSS Timelines.
Native CSS scroll() and view() animations running entirely on the compositor thread without scroll event listeners.
View code
<div class="scroll" tabindex="0" aria-label="Scroll inside to control the animation"><div class="track"><div class="sticky"><div class="tile">✳</div></div><div class="view-tile">VIEW TIMELINE</div></div></div>:root { color-scheme: dark; font: 15px system-ui, sans-serif; color: #dbff55; }
* { box-sizing: border-box; }
body { margin: 0; height: 100dvh; display: grid; place-items: center; overflow: hidden; background: transparent; }
.tile { display: grid; place-items: center; width: 68px; aspect-ratio: 1; border-radius: 18px; background: currentColor; }
.tile { background: #dbff55; color: #202415; font-size: 30px; }
canvas { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; }
button { font: inherit; color: #f3f1e9; background: #191919; border: 1px solid #ffffff66; padding: 8px 14px; border-radius: 24px; cursor: pointer; }
:focus-visible { outline: 2px solid #dbff55; outline-offset: -3px; }
.notice { max-width: 34ch; padding: 16px; color: #fff; }
@media (prefers-reduced-motion: reduce) { .sprite { animation-play-state: paused; } }
.scroll { width: min(90%, 550px); height: 86%; overflow: auto; border: 1px solid #ffffff55; }
.track { height: calc(100% + 340px); background: repeating-linear-gradient(transparent 0 31px, #ffffff18 31px 32px); }
.sticky { position: sticky; top: 0; height: min(45vh, 170px); display: grid; place-items: center; }
.tile { animation: roll linear both; animation-timeline: scroll(nearest block); }
.view-tile { width:max-content; margin: 170px auto 0; padding: 9px 16px; border: 1px solid; border-radius: 24px;
animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 100%;
}
@keyframes reveal { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes roll {
from { transform: translateX(-70px) rotate(-90deg) scale(.65); }
to { transform: translateX(70px) rotate(270deg) scale(1.35); }
}// CSS binds the keyframes to the nearest scroll container.
if (!CSS.supports('animation-timeline', 'scroll()')) {
const message = document.createElement('p');
message.className = 'notice';
message.textContent = 'Native scroll timelines are unavailable in this browser.';
document.querySelector('.sticky').append(message);
}