CKTIS / CSS
animation-trigger — reprodução de animações CSS controlada por acionadores
`animation-trigger` liga cada animação CSS a acionadores e ações nomeados, adiando a reprodução normal até atuar um acionador correspondente.
Versão: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxe
[ none | [ <dashed-ident> <animation-action>+ ]+ ]#animation-trigger liga cada animação CSS a acionadores e ações nomeados, adiando a reprodução normal até atuar um acionador correspondente.
O acionador temporal --arrival leva a animação de paused/0 a finished/200 e deixa o alvo transladado 100px. A origem calcula --arrival view() e a ligação --arrival play.
Sintaxe: [ none | [ <dashed-ident> <animation-action>+ ]+ ]#.
none mantém a animação sem acionador. Um nome tracejado com play, pause, reset, replay ou play-once define a resposta; uma contagem errada de ações é sintaticamente válida, mas não produz efeito. timeline-trigger reage a intervalos temporais, enquanto event-trigger é a variante de eventos do rascunho. Itens separados por vírgulas coordenam-se com a lista de animações, e animation repõe esta subpropriedade reset-only. Animation Triggers Level 1 é um Editor’s Draft em curso: apesar desta execução Chromium, produção exige consulta de funcionalidade e testes nos navegadores alvo.
Exemplos
document.body.innerHTML =
'<style>@keyframes travel{from{transform:translateX(0)}to{transform:translateX(100px)}}#viewport{height:80px;overflow:auto}#spacer{height:100px}#source{height:20px;timeline-trigger:--arrival view()}#target{width:10px;height:10px;animation:travel .2s linear both;animation-trigger:--arrival play}</style>' +
'<div id="viewport"><div id="spacer"></div><div id="source"></div><div style="height:100px"></div></div><div id="target"></div>';
const viewport=document.querySelector('#viewport');
const target=document.querySelector('#target');
await new Promise(requestAnimationFrame);
const animation=target.getAnimations()[0];
const before=animation.playState+'/'+Math.round(animation.currentTime||0);
viewport.scrollTop=100;
await new Promise(resolve=>setTimeout(resolve,350));
const matrix=new DOMMatrixReadOnly(getComputedStyle(target).transform);
console.log('before='+before+'; after='+animation.playState+'/'+Math.round(animation.currentTime||0)+'; x='+Math.round(matrix.m41)+'; trigger='+getComputedStyle(target).animationTrigger+'; timeline='+getComputedStyle(document.querySelector('#source')).timelineTrigger);Resultado
before=paused/0; after=finished/200; x=100; trigger=--arrival play; timeline=--arrival view()
`animation-trigger` liga cada animação CSS a acionadores e ações nomeados, adiando a reprodução normal até atuar um acionador correspondente.