CKTIS / CSS
@starting-style — estilo inicial de una transición
La regla @starting-style aporta un estilo previo a un elemento que no tenía estilo renderizado anteriormente.
Versión: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaxis
@starting-style { <rule-list> }@starting-style proporciona valores de partida solo para iniciar una transición cuando el evento de cambio anterior no aportó un estilo previo. Un elemento recién insertado o que vuelve de display: none es el caso habitual. La regla normal sigue definiendo el estado final opacity: 1, mientras el bloque puede aportar opacity: 0.
El ejemplo inserta a la vez dos elementos nuevos con transition. Solo el elemento cubierto recibe una animación; una CSSStartingStyleRule permanece en CSSOM y al pausar a mitad se obtiene opacidad calculada 0.5. El elemento de control sin la regla no crea animación.
No es un fotograma clave ni el valor inicial de una propiedad. Las declaraciones participan en la cascada normal y deben perder ante el estilo final para que haya cambio. Reinsertar dentro del mismo evento de estilo o usar una propiedad sin transición coincidente puede no iniciar el efecto.
Ejemplos
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
La regla @starting-style aporta un estilo previo a un elemento que no tenía estilo renderizado anteriormente.