> **Wichtig:** Stagger-Animationen mit ''animation-delay'' brauchen ''animation-fill-mode: backwards'' oder ''both'', damit die Elemente während der Wartezeit noch im Startzustand (z. B. ''opacity: 0'') bleiben und nicht kurz sichtbar aufblitzen.
===== Ladeanimationen: zwei klassische Muster =====
==== Spinner (Rotation) ====
@keyframes spin {
to { transform: rotate(360deg); }
}
.spinner {
width: 36px;
height: 36px;
border: 4px solid #e0e0e0;
border-top-color: #444;
border-radius: 50%;
animation: spin 0.75s linear infinite;
}
''linear'' ist bei Spinners entscheidend: Ein ''ease-in-out'' würde das Drehen ungleichmässig wirken lassen.
==== Bounce Dots ====
@keyframes bounce {
0%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(-10px); }
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #888;
animation: bounce 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
Die ''0%''- und ''100%''-Keyframes sind identisch — das sorgt für eine fliessende, endlose Wiederholung ohne abrupten Sprung.
===== animation-play-state: Pausieren =====
Eine laufende Animation kann per CSS oder JavaScript pausiert werden:
/* Per CSS – z. B. bei Hover: */
.spinner:hover {
animation-play-state: paused;
}
// Per JavaScript:
element.style.animationPlayState = 'paused';
element.style.animationPlayState = 'running';
===== Performance-Hinweis =====
Animieren Sie wenn immer möglich nur ''transform'' und ''opacity''. Diese Properties werden direkt auf der GPU berechnet und lösen kein teures **Reflow** (Neuberechnung des Layouts) aus:
/* ✅ Performant — GPU-beschleunigt: */
@keyframes gut {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* ⚠️ Langsamer — löst Reflow aus: */
@keyframes langsam {
from { height: 0; margin-top: 20px; }
to { height: 100px; margin-top: 0; }
}
===== Weiterführende Ressourcen =====
* 📺 [[https://www.youtube.com/watch?v=CAK5kTApkMU|Kevin Powell – Simplifying CSS animations]] (5 Min., Englisch)
* 📖 [[https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes|MDN – @keyframes]]
* 📖 [[https://developer.mozilla.org/en-US/docs/Web/CSS/animation|MDN – animation (Shorthand)]]
* 📖 [[https://www.joshwcomeau.com/animation/keyframe-animations/|Josh W. Comeau – Keyframe Animations]] (sehr empfehlenswert)