CKTIS / CSS
view() — průběh viditelnosti prvku v posuvné oblasti
`view()` vytváří pro `animation-timeline` anonymní osu sledující hlavní box prvku při průchodu nejbližší posuvnou oblastí.
Verze: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntaxe
view( [ <axis> || <'view-timeline-inset'> ]? )view() vytváří pro animation-timeline anonymní osu sledující hlavní box prvku při průchodu nejbližší posuvnou oblastí.
S view(block) dávají polohy 20/95/170px krytí 0/0.5/1; objekt je ViewTimeline, vypočtený zápis view() a varianta s odsazením má podporu true.
Gramatika: view( [ <axis> || <'view-timeline-inset'> ]? ).
Výchozí osa je block; existují také inline, x a y. Jedno či dvě odsazení jako 10px 20px zmenší rozsah; auto použije příslušné scroll-padding. V cover je 0% vstup počáteční hrany od konce a 100% výstup koncové hrany u začátku. Bez hlavního boxu, posuvné oblasti či přetečení je čas null.
Příklady
const style=document.createElement('style');style.textContent='@keyframes reveal{from{opacity:0}to{opacity:1}}.scroller{width:100px;height:100px;overflow:auto}.track{height:320px;padding-top:120px;box-sizing:border-box}.subject{height:50px;animation:reveal linear both;animation-timeline:view(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 settle=()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)));await settle();
const animation=subject.getAnimations()[0];const sample=async top=>{scroller.scrollTop=top;await settle();return getComputedStyle(subject).opacity};
const enter=await sample(20),middle=await sample(95),exit=await sample(170);
console.log('opacity='+enter+'/'+middle+'/'+exit+'; timeline='+animation.timeline.constructor.name+'; inset='+getComputedStyle(subject).animationTimeline+'; supported='+CSS.supports('animation-timeline','view(block 10px 20px)'));Výsledek
opacity=0/0.5/1; timeline=ViewTimeline; inset=view(); supported=true
`view()` vytváří pro `animation-timeline` anonymní osu sledující hlavní box prvku při průchodu nejbližší posuvnou oblastí.