CKTIS / CSS
@starting-style — style initial d’une transition
La règle @starting-style fournit un style avant changement à un élément sans style rendu auparavant.
Version : CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntaxe
@starting-style { <rule-list> }@starting-style fournit des valeurs de départ uniquement pour lancer une transition lorsque l’événement précédent n’offrait aucun style antérieur. Un nouvel élément ou le retour depuis display: none est le cas courant. La règle normale définit toujours l’état final opacity: 1, tandis que le bloc peut fournir opacity: 0.
L’exemple insère simultanément deux nouveaux éléments dotés de transition. Seul l’élément couvert reçoit une animation ; une CSSStartingStyleRule demeure dans CSSOM et une pause à mi-chemin donne l’opacité calculée 0.5. L’élément témoin sans cette règle ne crée aucune animation.
Ce n’est ni une image clé ni la valeur initiale d’une propriété. Les déclarations suivent la cascade normale et doivent perdre face au style final pour produire un changement. Une réinsertion dans le même événement de style ou une propriété sans transition correspondante peut ne pas lancer l’effet.
Exemples
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);Résultat
rule=CSSStartingStyleRule; animations=1/0; midpoint=0.5
La règle @starting-style fournit un style avant changement à un élément sans style rendu auparavant.