W3docs

Proprietà CSS animation-direction

La proprietà CSS animation-direction imposta come deve essere riprodotta un'animazione: in avanti, all'indietro o in cicli alternati. Guarda gli esempi ed esercitati.

La proprietà CSS animation-direction imposta come deve essere riprodotta un'animazione: in avanti, all'indietro o in cicli alternati. Il valore predefinito è normal.

Quando per una qualsiasi proprietà di animazione vengono specificati più valori separati da virgola, questi vengono applicati in ordine alle animazioni corrispondenti definite in animation-name.

La proprietà animation-direction è una delle proprietà CSS3.

Valore inizialenormal
Si applica aTutti gli elementi. Si applica anche agli pseudo-elementi ::before e ::after.
EreditataNo.
AnimabileNo.
VersioneCSS3
Sintassi DOMobject.style.animationDirection = "reverse"

Sintassi

Sintassi della proprietà CSS animation-direction

animation-direction: normal | reverse | alternate | alternate-reverse | initial | inherit;

Esempio della proprietà animation-direction:

Esempio della proprietà CSS animation-direction con il valore normal

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 120px;
        height: 120px;
        background: #ccc;
        position: relative;
        animation: myfirst 5s 1;
        animation-direction: normal;
      }
      @keyframes myfirst {
        0% {
          background: #8DC3CF;
          left: 0px;
          top: 0px;
        }
        25% {
          background: #1c87c9;
          left: 200px;
          top: 0px;
        }
        50% {
          background: #030E10;
          left: 200px;
          top: 200px;
        }
        75% {
          background: #666;
          left: 0px;
          top: 200px;
        }
        100% {
          background: #8ebf42;
          left: 0px;
          top: 0px;
        }
      }
    </style>
  </head>
  <body>
    <h2>Animation-direction example</h2>
    <p>Here the animation plays forwards.</p>
    <div></div>
  </body>
</html>

Esempio della proprietà animation-direction con il valore "reverse":

Esempio della proprietà CSS animation-direction con il valore reverse

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 100px;
        height: 100px;
        background: #ccc;
        position: relative;
        animation: myfirst 5s 1;
        animation-direction: reverse;
      }
      @keyframes myfirst {
        0% {
          background: #8DC3CF;
          left: 0px;
          top: 0px;
        }
        25% {
          background: #1c87c9;
          left: 200px;
          top: 0px;
        }
        50% {
          background: #030E10;
          left: 200px;
          top: 200px;
        }
        75% {
          background: #666;
          left: 0px;
          top: 200px;
        }
        100% {
          background: #8ebf42;
          left: 0px;
          top: 0px;
        }
      }
    </style>
  </head>
  <body>
    <h2>Animation-direction example</h2>
    <p>In this example the animation plays as reverse.</p>
    <div></div>
  </body>
</html>

Esempio della proprietà animation-direction con il valore "alternate":

Esempio della proprietà CSS animation-direction con il valore alternate

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 100px;
        height: 100px;
        background: #ccc;
        position: relative;
        animation: myfirst 5s 2;
        animation-direction: alternate;
      }
      @keyframes myfirst {
        0% {
          background: #8DC3CF;
          left: 0px;
          top: 0px;
        }
        25% {
          background: #1c87c9;
          left: 200px;
          top: 0px;
        }
        50% {
          background: #030E10;
          left: 200px;
          top: 200px;
        }
        75% {
          background: #666;
          left: 0px;
          top: 200px;
        }
        100% {
          background: #8ebf42;
          left: 0px;
          top: 0px;
        }
      }
    </style>
  </head>
  <body>
    <h2>Animation-direction example</h2>
    <p>Here the animation plays first forwards, then backwards.</p>
    <div></div>
  </body>
</html>

Esempio della proprietà animation-direction con il valore "alternate-reverse":

Esempio della proprietà CSS animation-direction con il valore alternate-reverse

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 100px;
        height: 100px;
        background: #ccc;
        position: relative;
        animation: myfirst 5s 2;
        animation-direction: alternate-reverse;
      }
      @keyframes myfirst {
        0% {
          background: #8DC3CF;
          left: 0px;
          top: 0px;
        }
        25% {
          background: #1c87c9;
          left: 200px;
          top: 0px;
        }
        50% {
          background: #030E10;
          left: 200px;
          top: 200px;
        }
        75% {
          background: #666;
          left: 0px;
          top: 200px;
        }
        100% {
          background: #8ebf42;
          left: 0px;
          top: 0px;
        }
      }
    </style>
  </head>
  <body>
    <h2>Animation-direction example</h2>
    <p>Here the animation plays backwards, then forwards.</p>
    <div></div>
  </body>
</html>

Valori

ValoreDescrizioneProvalo
normalÈ il valore predefinito: l'animazione viene riprodotta in avanti.Provalo »
reverseL'animazione viene riprodotta all'indietro. Ogni volta che esegui l'animazione, questa si reimposta sulla fine e ricomincia. Anche la funzione di timing viene invertita.Provalo »
alternateDapprima l'animazione si muove in avanti, poi all'indietro. Per essere visibile richiede animation-iteration-count ≥ 2.Provalo »
alternate-reverseDapprima l'animazione si muove all'indietro, poi in avanti. Per essere visibile richiede animation-iteration-count ≥ 2.Provalo »
initialImposta la proprietà al suo valore predefinito.
inheritEredita la proprietà dall'elemento genitore.

Pratica

Pratica
What are the possible values for the CSS Animation-direction property?
What are the possible values for the CSS Animation-direction property?
Was this page helpful?