Propriedade animation-play-state

A propriedade animation-play-state permite definir o estado de uma animação: se está sendo executada ou se está pausada.

Sintaxe

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

Valores

Valor Descrição
paused A animação está pausada.
running A animação está sendo executada.

Valor padrão: running.

Exemplo

Neste exemplo, a animação será iniciada ao passar o mouse sobre o elemento e será pausada quando o mouse for removido do 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;
}

Результат:

Exemplo . Passando o mouse sobre outro elemento

Agora, a animação será iniciada passando o mouse sobre outro elemento e será pausada quando o mouse for removido dele:

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;
}

Результат:

Veja também