animation

Experimente

/* @keyframes duration | timing-function | delay |
iteration-count | direction | fill-mode | play-state | name */
animation: 3s ease-in 1s 2 reverse both paused slidein;

/* @keyframes name | duration | timing-function | delay */
animation: 3s linear 1s slidein;

/* @keyframes name | duration */
animation: slidein 3s;

A description of which properties are animatable (en-US) is available; it's worth noting that this description is also valid for CSS transitions (en-US).

Initial valueas each of the properties of the shorthand:
Aplica-se aall elements, ::before and ::after pseudo-elements
Inheritednão
Computed valueas each of the properties of the shorthand:
Animation typeNot animatable

Syntax

A propriedade animation é especificada como uma ou mais animações, separadas por commas.

Cada animação individual é especificada como:

A ondem dos valores definidos dentro de cada animação é importante: o primeiro valor pode ser analisado com um <time> é atribuido para o animation-duration (en-US), and the second one is assigned to animation-delay.

The order within each animation definition is also important for distinguishing animation-name (en-US) values from other keywords. When parsed, keywords that are valid for properties other than animation-name (en-US), and whose values were not found earlier in the shorthand, must be accepted for those properties rather than for animation-name (en-US). Furthermore, when serialized, default values of other properties must be output in at least the cases necessary to distinguish an animation-name (en-US) that could be a value of another property, and may be output in additional cases.

Values

<single-animation-iteration-count>

The number of times the animation is played. The value must be one of those available in animation-iteration-count (en-US).

<single-animation-direction>

The direction in which the animation is played. The value must be one of those available in animation-direction (en-US).

<single-animation-fill-mode>

Determines how styles should be applied to the animation's target before and after its execution. The value must be one of those available in animation-fill-mode.

<single-animation-play-state>

Determines whether the animation is playing or not. The value must be one of those available in animation-play-state (en-US).

Formal syntax

animation = 
<single-animation>#

<single-animation> =
<time> ||
<easing-function> ||
<time> ||
<single-animation-iteration-count> ||
<single-animation-direction> ||
<single-animation-fill-mode> ||
<single-animation-play-state> ||
[ none | <keyframes-name> ]

<easing-function> =
linear |
<linear-easing-function> |
<cubic-bezier-easing-function> |
<step-easing-function>

<single-animation-iteration-count> =
infinite |
<number [0,∞]>

<single-animation-direction> =
normal |
reverse |
alternate |
alternate-reverse

<single-animation-fill-mode> =
none |
forwards |
backwards |
both

<single-animation-play-state> =
running |
paused

<keyframes-name> =
<custom-ident> (en-US) |
<string> (en-US)

<linear-easing-function> =
linear( <linear-stop-list> )

<cubic-bezier-easing-function> =
ease |
ease-in |
ease-out |
ease-in-out |
cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )

<step-easing-function> =
step-start |
step-end |
steps( <integer> (en-US) [, <step-position> ]? )

<linear-stop-list> =
[ <linear-stop> ]#

<step-position> =
jump-start |
jump-end |
jump-none |
jump-both |
start |
end

<linear-stop> =
<number> &&
<linear-stop-length>?

<linear-stop-length> =
<percentage> (en-US){1,2}

Examples

Cylon Eye

<div class="view_port">
  <div class="polling_message">
    Listening for dispatches
  </div>
  <div class="cylon_eye"></div>
</div>
.polling_message {
  color: white;
  float: left;
  margin-right: 2%;
}

.view_port {
  background-color: black;
  height: 25px;
  width: 100%;
  overflow: hidden;
}

.cylon_eye {
  background-color: red;
  background-image: linear-gradient(to right,
      rgba(0, 0, 0, .9) 25%,
      rgba(0, 0, 0, .1) 50%,
      rgba(0, 0, 0, .9) 75%);
  color: white;
  height: 100%;
  width: 20%;

  -webkit-animation: 4s linear 0s infinite alternate move_eye;
          animation: 4s linear 0s infinite alternate move_eye;
}

@-webkit-keyframes move_eye { from { margin-left: -20%; } to { margin-left: 100%; }  }
        @keyframes move_eye { from { margin-left: -20%; } to { margin-left: 100%; }  }

See Using CSS animations for additional examples.

Accessibility concerns

Blinking and flashing animation can be problematic for people with cognitive concerns such as Attention Deficit Hyperactivity Disorder (ADHD). Additionally, certain kinds of motion can be a trigger for Vestibular disorders, epilepsy, and migraine and Scotopic sensitivity.

Consider providing a mechanism for pausing or disabling animation, as well as using the Reduced Motion Media Query (en-US) to create a complimentary experience for users who have expressed a preference for no animated experiences.

Specifications

Specification Status Comment
CSS Animations Level 1
The definition of 'animation' in that specification.
Rascunho atual Initial definition.

Compatibilidade com navegadores

BCD tables only load in the browser

Quantum CSS notes

  • Gecko has a bug whereby when you animate an offscreen element onscreen but specify a delay, Gecko does not repaint on some platforms, e.g. Windows (bug 1383239). This has been fixed in Firefox's new parallel CSS engine (also known as Quantum CSS or Stylo, planned for release in Firefox 57).
  • Another Gecko bug means that <details> elements can't be made open by default using the open attribute if they have an animation active on them (bug 1382124). Quantum CSS fixes this.
  • A further bug means that animations using em units are not affected by changes to the font-size on the animated element's parent, whereas they should be (bug 1254424). Quantum CSS fixes this.

See also