Die @keyframes-Regel
Die Regel @keyframes definiert Keyframes
für Animationen. Ein Keyframe repräsentiert
verschiedene Eigenschaften unseres CSS-Elements, zum Beispiel Position,
Größe, Farbe und andere, die auf das Element zu einem
bestimmten Zeitpunkt angewendet werden.
Syntax
@keyframes Animation-Name {
Keyframes
}
Beispiel
Keyframes definieren:
<div id="elem"></div>
@keyframes anim {
from {
margin-left: 0px;
}
to {
margin-left: 400px;
}
}
#elem {
animation: anim 3s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
:
Beispiel
Lassen Sie uns nun unser Quadrat mit Hilfe einer Animation von oben nach unten bewegen:
<div id="elem"></div>
@keyframes anim {
from {
margin-top: 0%;
}
to {
margin-top: 10%;
}
}
#elem {
animation: anim 2s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
:
Beispiel
Lassen Sie uns die Breite unserer Form mit Hilfe einer Animation vergrößern, indem wir Keyframes in Prozent angeben:
<div id="elem"></div>
@keyframes anim {
from {
width: 10%;
}
to {
width: 40%;
}
}
#elem {
animation: anim 2s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
:
Beispiel
Lassen Sie uns nun die Deckkraft unserer Form ändern:
<div id="elem"></div>
@keyframes anim {
from {
background-color: #467CBC;
}
to {
background-color: #C2DDFD;
}
}
#elem {
animation: anim 2s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
:
Siehe auch
-
alle Eigenschaften für CSS-Animationen
animation-name,animation-duration,animation-delay,animation-timing-function,animation-iteration-count,animation-direction,animation-fill-mode,animation-play-state,keyframes -
transition- fließende Übergänge (Animation beim Überfahren des Elements mit der Maus)