CKTIS / CSS
@starting-style — estilo inicial de uma transição
A regra @starting-style fornece um estilo anterior a um elemento que não tinha estilo previamente renderizado.
Versão: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxe
@starting-style { <rule-list> }@starting-style fornece valores de partida apenas para iniciar uma transição quando o evento anterior não tinha estilo prévio. Um elemento acabado de inserir ou que regressa de display: none é o caso habitual. A regra normal continua a definir o estado final opacity: 1, enquanto o bloco pode fornecer opacity: 0.
O exemplo insere ao mesmo tempo dois elementos novos com transition. Apenas o elemento abrangido recebe uma animação; uma CSSStartingStyleRule permanece no CSSOM e a pausa a meio produz opacidade calculada 0.5. O elemento de controlo sem a regra não cria animação.
Não é um fotograma-chave nem o valor inicial de uma propriedade. As declarações participam na cascata normal e têm de perder para o estilo final para ocorrer mudança. Reinserir no mesmo evento de estilo ou usar uma propriedade sem transição correspondente pode não iniciar o efeito.
Exemplos
const style=document.createElement('style');
style.textContent='.probe { opacity: 1; transition: opacity 1000ms linear; } @starting-style { .with-start { opacity: 0; } }';
document.head.append(style);
const withStart=document.createElement('div'); withStart.className='probe with-start'; withStart.textContent='with';
const control=document.createElement('div'); control.className='probe'; control.textContent='control';
document.body.append(withStart,control);
await new Promise(requestAnimationFrame);
const animation=withStart.getAnimations()[0];
if(!animation) throw new Error('starting-style transition did not start');
animation.pause(); await animation.ready; animation.currentTime=500;
const rule=style.sheet.cssRules[1];
console.log('rule='+rule.constructor.name+'; animations='+withStart.getAnimations().length+'/'+control.getAnimations().length+'; midpoint='+getComputedStyle(withStart).opacity);Resultado
rule=CSSStartingStyleRule; animations=1/0; midpoint=0.5
A regra @starting-style fornece um estilo anterior a um elemento que não tinha estilo previamente renderizado.