aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/css/animation-fill-mode/index.html
blob: 8e52a69d44d7fb74e86daeb5cd5c85e5b7d909d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
title: animation-fill-mode
slug: Web/CSS/animation-fill-mode
translation_of: Web/CSS/animation-fill-mode
---
<div>{{CSSRef}}</div>

<p>A propriedade CSS <strong><code>animation-fill-mode</code></strong> define como uma animação <a href="https://wiki.developer.mozilla.org/en/CSS">CSS</a> aplica estilos ao seu destino antes e depois de sua execução.</p>

<div>{{EmbedInteractiveExample("pages/css/animation-fill-mode.html")}}</div>



<p>It is often convenient to use the shorthand property {{cssxref("animation")}} to set all animation properties at once.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush: css no-line-numbers notranslate">/* Single animation */
animation-fill-mode: none;
animation-fill-mode: forwards;
animation-fill-mode: backwards;
animation-fill-mode: both;

/* Multiple animations */
animation-fill-mode: none, backwards;
animation-fill-mode: both, forwards, none;
</pre>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>none</code></dt>
 <dd>A animação não aplicará nenhum estilo ao destino quando não estiver em execução. Em vez disso, o elemento será exibido usando quaisquer outras regras CSS aplicadas a ele. Este é o valor padrão.</dd>
 <dt><code>forwards</code></dt>
 <dd>The target will retain the computed values set by the last <a href="/en-US/docs/CSS/@keyframes">keyframe</a> encountered during execution. The last keyframe depends on the value of {{cssxref("animation-direction")}} and {{cssxref("animation-iteration-count")}}:
 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col"><code>animation-direction</code></th>
    <th scope="col"><code>animation-iteration-count</code></th>
    <th scope="col">last keyframe encountered</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td><code>normal</code></td>
    <td>even or odd</td>
    <td><code>100%</code> or <code>to</code></td>
   </tr>
   <tr>
    <td><code>reverse</code></td>
    <td>even or odd</td>
    <td><code>0%</code> or <code>from</code></td>
   </tr>
   <tr>
    <td><code>alternate</code></td>
    <td>even</td>
    <td><code>0%</code> or <code>from</code></td>
   </tr>
   <tr>
    <td><code>alternate</code></td>
    <td>odd</td>
    <td><code>100%</code> or <code>to</code></td>
   </tr>
   <tr>
    <td><code>alternate-reverse</code></td>
    <td>even</td>
    <td><code>100%</code> or <code>to</code></td>
   </tr>
   <tr>
    <td><code>alternate-reverse</code></td>
    <td>odd</td>
    <td><code>0%</code> or <code>from</code></td>
   </tr>
  </tbody>
 </table>
 </dd>
 <dt><code>backwards</code></dt>
 <dd>The animation will apply the values defined in the first relevant <a href="/en-US/docs/CSS/@keyframes">keyframe</a> as soon as it is applied to the target, and retain this during the {{cssxref("animation-delay")}} period. The first relevant keyframe depends on the value of {{cssxref("animation-direction")}}:
 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col"><code>animation-direction</code></th>
    <th scope="col">first relevant keyframe</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td><code>normal</code> or <code>alternate</code></td>
    <td><code>0%</code> or <code>from</code></td>
   </tr>
   <tr>
    <td><code>reverse</code> or <code>alternate-reverse</code></td>
    <td><code>100%</code> or <code>to</code></td>
   </tr>
  </tbody>
 </table>
 </dd>
 <dt><code>both</code></dt>
 <dd>The animation will follow the rules for both forwards and backwards, thus extending the animation properties in both directions.</dd>
</dl>

<div class="note">
<p><strong>Note</strong>: When you specify multiple comma-separated values on an <code>animation-*</code> property, they will be assigned to the animations specified in the {{cssxref("animation-name")}} property in different ways depending on how many there are. For more information, see <a href="/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations#Setting_multiple_animation_property_values">Setting multiple animation property values</a>.</p>
</div>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox notranslate">{{csssyntax}}
</pre>

<h2 id="Example">Example</h2>

<p>You can see the effect of <code>animation-fill-mode</code> in the following example. It demonstrates how, for an animation that runs for an infinite time, you can cause it to remain in its final state rather than reverting to the original state (which is the default).</p>

<h3 id="HTML">HTML</h3>

<pre class="brush: html notranslate">&lt;p&gt;Move your mouse over the gray box!&lt;/p&gt;
&lt;div class="demo"&gt;
 &lt;div class="growsandstays"&gt;This grows and stays big.&lt;/div&gt;
  &lt;div class="grows"&gt;This just grows.&lt;/div&gt;
&lt;/div&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css notranslate">.demo {
  border-top: 100px solid #ccc;
  height: 300px;
}

@keyframes grow {
  0% { font-size: 0; }
  100% { font-size: 40px; }
}

.demo:hover .grows {
  animation-name: grow;
  animation-duration: 3s;
}

.demo:hover .growsandstays {
  animation-name: grow;
  animation-duration: 3s;
  animation-fill-mode: forwards;
}</pre>

<p>{{EmbedLiveSample('Example',700,300)}}</p>

<p>See <a href="/en/CSS/CSS_animations">CSS animations</a> for more examples.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Animations', '#animation-fill-mode', 'animation-fill-mode')}}</td>
   <td>{{Spec2('CSS3 Animations')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<p>{{cssinfo}}</p>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("css.properties.animation-fill-mode")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/CSS/CSS_Animations/Using_CSS_animations">Using CSS animations</a></li>
 <li>JavaScript {{domxref("AnimationEvent")}} API</li>
</ul>