Eienskap animation-play-state

Die eienskap animation-play-state laat toe om die staat van die animasie te stel: dit word gespeel of is op pouse.

Sintaksis

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

Waardes

Waarde Beskrywing
paused Die animasie is op pouse.
running Die animasie speel af.

Verstekwaarde: running.

Voorbeeld

In hierdie voorbeeld sal die animasie begin wanneer die muis oor die element beweeg, en stop wanneer die muis van die element af beweeg word:

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

Результат:

Voorbeeld . Beweeg oor 'n ander element

En nou sal die animasie begin wanneer die muis oor 'n ander element beweeg, en stop wanneer die muis daarvan af beweeg word:

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

Результат:

Sien ook