CKTIS / CSS
scroll() — línea temporal anónima de progreso de desplazamiento
`scroll()` crea para `animation-timeline` una línea temporal anónima eligiendo un contenedor desplazable y un eje.
Versión: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxis
scroll( [ <scroller> || <axis> ]? )scroll() crea para animation-timeline una línea temporal anónima eligiendo un contenedor desplazable y un eje.
Un contenedor real con scroll(nearest block) en las posiciones 0/100/200px produce opacidad 0/0.5/1; el objeto es ScrollTimeline. Una línea propia sin desbordamiento queda inactiva y la sintaxis se admite true.
Gramática: scroll( [ <scroller> || <axis> ]? ).
Los valores predeterminados son nearest y block. root selecciona la ventana del documento, self la caja principal del elemento; también existen inline, x y y. El progreso es scroll offset / (scrollable overflow - scrollport); sin desbordamiento o con self no desplazable, el tiempo es null. El origen sigue writing-mode incluso en ejes físicos, y la duración finita es 100%.
Ejemplos
const style=document.createElement('style');style.textContent='@keyframes reveal{from{opacity:0}to{opacity:1}}.scroller{width:100px;height:100px;overflow:auto}.track{height:300px}.subject{animation:reveal linear both;animation-timeline:scroll(nearest block)}.inactive{animation:reveal linear both;animation-timeline:scroll(self block)}';document.head.append(style);
const scroller=document.createElement('div');scroller.className='scroller';const track=document.createElement('div');track.className='track';const subject=document.createElement('div');subject.className='subject';track.append(subject);scroller.append(track);document.body.append(scroller);
const inactive=document.createElement('div');inactive.className='inactive';document.body.append(inactive);
const settle=()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)));
await settle();const animation=subject.getAnimations()[0];const inactiveAnimation=inactive.getAnimations()[0];
const sample=async top=>{scroller.scrollTop=top;await settle();return getComputedStyle(subject).opacity};
const top=await sample(0),middle=await sample(100),end=await sample(200);
console.log('opacity='+top+'/'+middle+'/'+end+'; timeline='+animation.timeline.constructor.name+'; inactive='+(inactiveAnimation.currentTime===null)+'; supported='+CSS.supports('animation-timeline','scroll(nearest block)'));Resultado
opacity=0/0.5/1; timeline=ScrollTimeline; inactive=true; supported=true
`scroll()` crea para `animation-timeline` una línea temporal anónima eligiendo un contenedor desplazable y un eje.