CKTIS / CSS
transition-delay — časovni zamik začetka prehoda
Lastnost transition-delay določa časovni zamik začetka prehoda CSS: pozitivne vrednosti prehod odložijo, negativne pa preskočijo njegov začetek, če po zamiku še ostane del prehoda.
Različica: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaksa
transition-delay: <time>#;transition-delay sprejema časovne vrednosti v s ali ms. Začetna vrednost je 0s; lastnost se ne deduje in ni animabilna. Sama ne sproži spremembe sloga.
Pozitivne vrednosti odložijo prehod in med čakanjem ohranijo začetno vrednost. Pri 0s se začne takoj. Pri negativnem zamiku se prehod začne takoj na poznejši točki poteka, vendar le, če je vsota trajanja in zamika pozitivna. Pri transition-duration: 1s zamik -250ms preskoči prvih 250 ms. Če je absolutna vrednost negativnega zamika enaka trajanju ali ga presega, se prehod ne začne.
Vrednosti, ločene z vejicami, ustrezajo vrstnemu redu transition-property: manjkajoče vrednosti se ponovijo, odvečne pa prezrejo. V okrajšani obliki transition prvi čas pomeni trajanje, drugi pa zamik. Čakalnega časa ne zamenjuj s trajanjem same spremembe.
Primeri
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Transition start delay</title>
<style>
.box {
width: 60px;
height: 60px;
margin-block-start: 12px;
background: navy;
transform: translateX(0px);
transition-property: transform;
transition-duration: 1s;
transition-timing-function: linear;
transition-delay: 500ms;
}
#move:checked ~ .box { transform: translateX(120px); }
</style>
</head>
<body>
<input id="move" type="checkbox">
<label for="move">Move the square</label>
<div class="box" aria-hidden="true"></div>
<script>
const move = document.getElementById('move');
const box = document.querySelector('.box');
const style = getComputedStyle(box);
console.log(`Computed delay: ${style.transitionDelay}`);
// Commit the starting transform before changing the checked state.
const horizontalOffset = () => Math.round(new DOMMatrixReadOnly(style.transform).m41);
console.log(`Before checking: ${horizontalOffset()}px`);
move.checked = true;
const [motion] = box.getAnimations();
motion.pause();
for (const time of [250, 1000, 1500]) {
motion.currentTime = time;
console.log(`At ${time}ms: ${horizontalOffset()}px`);
}
// Finish the demonstration and leave the checkbox usable.
motion.finish();
</script>
</body>
</html>Rezultat
Computed delay: 0.5s Before checking: 0px At 250ms: 0px At 1000ms: 60px At 1500ms: 120px
Prikazana koda in navedeni rezultat sta bila preverjena v izoliranem okolju z metodo, zapisano v dokazilu o preverjanju te natančne različice.