База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / CSS

scroll() — анонимна времева ос на напредъка при превъртане

`scroll()` създава за `animation-timeline` анонимна ос чрез избор на контейнер за превъртане и ос.

Версия: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Синтаксис

scroll( [ <scroller> || <axis> ]? )

scroll() създава за animation-timeline анонимна ос чрез избор на контейнер за превъртане и ос.

Реален контейнер с scroll(nearest block) при позиции 0/100/200px дава непрозрачност 0/0.5/1; обектът е ScrollTimeline. Собствена ос без преливане е неактивна, а поддръжката на синтаксиса е true.

Граматика: scroll( [ <scroller> || <axis> ]? ).

По подразбиране са nearest и block. root избира изгледа на документа, self главната кутия на елемента; осите включват inline, x и y. Напредъкът е scroll offset / (scrollable overflow - scrollport); без преливане или при непревъртащо се self времето е null. Началото следва writing-mode дори при физически оси, а продължителността на крайна ос е 100%.

Примери

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)'));

Резултат

opacity=0/0.5/1; timeline=ScrollTimeline; inactive=true; supported=true

`scroll()` създава за `animation-timeline` анонимна ос чрез избор на контейнер за превъртане и ос.

Източници