Propiedad animation-play-state

La propiedad animation-play-state permite establecer el estado de la animación: se reproduce o está en pausa.

Sintaxis

cssselector {
  animation-play-state: paused | running;
}

Valores

Valor Descripción
paused La animación está en pausa.
running La animación se reproduce.

Valor por defecto: running.

Ejemplo

En este ejemplo, la animación se iniciará al pasar el ratón sobre el elemento, y se detendrá cuando el ratón se retire del elemento:

html<div id="elem"></div>
css@keyframes move {
  from {
    width: 200px;
  }
  to {
    width: 400px;
  }
}

#elem {
  animation-play-state: paused;
  animation-duration: 1s;
  animation-name: move;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  border: 1px solid black;
  height: 50px;
}
#elem:hover {
  animation-play-state: running;
}

Результат:

Ejemplo . Pasar el ratón sobre otro elemento

Y ahora la animación se iniciará al pasar el ratón sobre otro elemento, y al retirar el ratón de él, se detendrá:

html<div id="target"></div>
<div id="elem"></div>
css@keyframes move {
  from {
    margin-left: 0;
  }
  to {
    margin-left: 400px;
  }
}

#target {
  border: 1px solid red;
  margin-bottom: 10px;
  width: 50px;
  height: 50px;
}

#elem {
  animation-play-state: paused;
  animation-duration: 3s;
  animation-name: move;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  border: 1px solid black;
  width: 50px;
  height: 50px;
}

#target:hover + #elem {
  animation-play-state: running;
  border: 1px solid green;
}

Результат:

Véase también