-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
419 lines (321 loc) · 16.4 KB
/
Overview.bs
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<pre class=metadata>
Title: CSS Timing Functions Level 1
Status: ED
Work Status: Refining
Shortname: css-timing
Level: 1
Group: csswg
ED: https://drafts.csswg.org/css-timing/
TR: https://www.w3.org/TR/css-timing-1/
Editor: Brian Birtles, Mozilla https://www.mozilla.org/, bbirtles@mozilla.com, w3cid 43194
Editor: Dean Jackson, Apple Inc https://www.apple.com/, dino@apple.com, w3cid 42080
Editor: Matt Rakow, Microsoft, w3cid 62267
Editor: Shane Stephens, Google Inc, shans@google.com, w3cid 47691
Abstract: This CSS module describes a way for authors to define a transformation
to be applied to the time of an animation. This can be used to produce
animations that mimic physical phenomena such as momentum or to
cause the animation to move in discrete steps producing robot-like
movement.
</pre>
<pre class=biblio>
{
"FUND-COMP-GRAPHICS": {
"title": "Fundamentals of Computer Graphics",
"authors": [
"Peter Shirley",
"Michael Ashikhmin",
"Steve Marschner"
],
"date": "2009",
"publisher": "A K Peters Limited"
}
}
</pre>
Introduction {#introduction}
============================
<em>This section is not normative.</em>
It is often desirable to control the rate at which an animation progresses.
For example, gradually increasing the speed at which an element moves can
give the element a sense of weight as it appears to gather momentum.
This can be used to produce user intuitive interface elements or convincing
cartoon props that behave like their physical counterparts.
Alternatively, it is sometimes desirable for animation to move forwards in
distinct steps such as a segmented wheel that rotates such that the segments
always appear in the same position.
[=Timing functions=] provide a means to transform animation time by taking an
input progress value and producing a corresponding transformed output progress
value.
<figure>
<img src="timing-function-example.svg" width="350"
alt="Example of a timing function that produces an ease-in effect.">
<figcaption>
Example of a timing function that produces an ease-in effect.
Given an input progress of 0.7, the timing function scales the
value to produce an output progress of 0.52.
By applying this timing function, the animation will progress more
slowly at first but then gradually progress more quickly.
</figcaption>
</figure>
Timing functions {#timing-functions}
====================================
A <dfn export>timing function</dfn> takes an [=input progress value=] and
produces an [=output progress value=].
A [=timing function=] must be a pure function meaning that for a given set of
inputs, it always produces the same [=output progress value=].
The <dfn>input progress value</dfn> is a real number in the range [-∞,
∞].
Typically, the [=input progress value=] is in the range [0, 1] but this may
not be the case when [=timing functions=] are chained together.
The <dfn>output progress value</dfn> is a real number in the
range [-∞, ∞].
Some types of timing function also take an additional boolean [=before flag=]
input which is defined subsequently.
This specification defines four types of timing functions whose definitions
follow.
The syntax for specifying a [=timing function=] is as follows:
<div class="prod"><dfn type><timing-function></dfn> =
''linear'' |
<<cubic-bezier-timing-function>> |
<<step-timing-function>> |
<<frames-timing-function>></div>
The linear timing function: ''linear'' {#linear-timing-function-section}
------------------------------------------------------------------------
The <dfn export>linear timing function</dfn> is an identity function
meaning that its [=output progress value=] is equal to the
[=input progress value=] for all inputs.
The syntax for the [=linear timing function=] is simply the
<dfn dfn-type=value for=timing-function>linear</dfn> keyword.
Cubic Bézier timing functions: ''ease'', ''ease-in'', ''ease-out'', ''ease-in-out'', ''cubic-bezier()'' {#cubic-bezier-timing-functions}
---------------------------------------------------------------------
A <dfn export>cubic Bézier timing function</dfn> is a type of [=timing
function=] defined by four real numbers that specify the two control
points, <var>P1</var> and <var>P2</var>, of a cubic Bézier curve whose
end points <var ignore>P0</var> and <var ignore>P3</var> are fixed at (0, 0) and
(1, 1) respectively.
The <var>x</var> coordinates of <var>P1</var> and <var>P2</var> are
restricted to the range [0, 1].
The mapping from input progress to output progress is performed by
determining the corresponding <var>y</var> value ([=output progress value=]) for
a given <var>x</var> value ([=input progress value=]).
The evaluation of this curve is covered in many sources such as
[[FUND-COMP-GRAPHICS]].
<figure>
<img src="cubic-bezier-timing-curve.svg" width="500"
alt="A cubic Bezier curve used as a timing function.">
<figcaption>
A cubic Bézier curve used as a timing function.<br>
The shape of the curve is determined by the location of the control
points <var>P1</var> and <var>P2</var>.<br>
Input progress values serve as <var>x</var> values of the curve,
whilst the <var>y</var> values are the output progress values.
</figcaption>
</figure>
For [=input progress values=] outside the range [0, 1], the curve is extended
infinitely using tangent of the curve at the closest endpoint as follows:
* For [=input progress values=] less than zero,
1. If the <var>x</var> value of P1 is greater than zero, use
a straight line that passes through P1 and P0 as the tangent.
1. Otherwise, if the <var>x</var> value of P2 is greater than
zero, use a straight line that passes through P2 and P0 as the tangent.
1. Otherwise, let the [=output progress value=] be zero for all
[=input progress values=] in the range [-∞, 0).
* For [=input progress values=] greater than one,
1. If the <var>x</var> value of P2 is less than one, use
a straight line that passes through P2 and P3 as the tangent.
1. Otherwise, if the <var>x</var> value of P1 is less than
one, use a straight line that passes through P1 and P3 as the tangent.
1. Otherwise, let the [=output progress value=] be one for all
[=input progress values=] in the range (1, ∞].
A <a>cubic Bézier timing function</a> may be specified as a string
using the following syntax (using notation from [[!CSS3VAL]]):
<div class="prod"><dfn type><cubic-bezier-timing-function></dfn> =
''ease'' | ''ease-in'' | ''ease-out'' | ''ease-in-out'' |
<span class="atom"><a lt="cubic-bezier()"
function>cubic-bezier</a>(<<number>>, <<number>>, <<number>>,
<<number>>)</span></div>
The meaning of each value is as follows:
<dl dfn-type="value" dfn-for="cubic-bezier-timing-function, <cubic-bezier-timing-function>">
: <dfn>ease</dfn>
:: Equivalent to cubic-bezier(0.25, 0.1, 0.25, 1).
: <dfn>ease-in</dfn>
:: Equivalent to cubic-bezier(0.42, 0, 1, 1).
: <dfn>ease-out</dfn>
:: Equivalent to cubic-bezier(0, 0, 0.58, 1).
: <dfn>ease-in-out</dfn>
:: Equivalent to cubic-bezier(0.42, 0, 0.58, 1).
: <dt><dfn function lt="cubic-bezier()">cubic-bezier(<<number>>, <<number>>, <<number>>, <<number>>)</dfn></dt>
:: Specifies a <a>cubic Bézier timing function</a>.
The four numbers specify points <var>P1</var> and <var>P2</var> of
the curve as (<var ignore>x1</var>, <var ignore>y1</var>, <var
ignore>x2</var>, <var ignore>y2</var>).
Both <var>x</var> values must be in the range [0, 1] or the definition is
invalid.
</dl>
The keyword values listed above are illustrated below.
<figure>
<img src="curve-keywords.svg" width="500"
alt="The timing functions produced by keyword values.">
<figcaption>
The timing functions produced by each of cubic Bézier timing
function keyword values.
</figcaption>
</figure>
Step timing functions: ''step-start'', ''step-end'', ''steps()'' {#step-timing-functions}
----------------------------------------------------------------
A <dfn>step timing function</dfn> is a type of <a>timing function</a>
that divides the input time into a specified number of intervals that
are equal in length.
Some example step timing functions are illustrated below.
<figure>
<img src="step-timing-func-examples.svg" width="500"
alt="Example step timing functions.">
<figcaption>
Example step timing functions.
In each case the domain is the input progress whilst the range
represents the output progress produced by the step function.<br>
The first row shows the function for each transition point when only
one step is specified whilst the second row shows the same for three
steps.
</figcaption>
</figure>
A [=step timing function=] is defined by a non-zero positive number of
<dfn>steps</dfn>, and a <dfn>step position</dfn> property that may be either
<a value for="steps()">start</a> or <a value for="steps()">end</a>.
At the exact point where a step occurs the result of the function is
conceptually the top of the step. However, an additional <dfn>before flag</dfn>
passed as input to the [=step timing function=], if true, will cause the
result of the function to correspond to the bottom of the step at the step
point.
The [=output progress value=] is calculated from the [=input progress value=]
and [=before flag=] as follows:
1. Calculate the <var>current step</var> as <code>floor([=input progress
value=] × [=steps=])</code>.
1. If the [=step position=] property is <a value for="steps()">start</a>,
increment <var>current step</var> by one.
1. If <em>both</em> of the following conditions are true:
* the [=before flag=] is set, <em>and</em>
* [=input progress value=] × [=steps=] mod 1 equals zero
(that is, if [=input progress value=] × [=steps=] is
integral), then
decrement <var>current step</var> by one.
1. If [=input progress value=] ≥ 0 and <var>current step</var> < 0,
let <var>current step</var> be zero.
1. If [=input progress value=] ≤ 1 and <var>current step</var> >
[=steps=], let <var>current step</var> be [=steps=].
<div class=note>
Steps 4 and 5 in this procedure ensure that given an [=input progress
value=] in the range [0, 1], a step timing function does not produce an
[=output progress value=] outside that range.
For example, although mathematically we might expect that a step timing
function with a [=step position=] of <a value for="steps()">start</a>
would step up when the [=input progress value=] is 1, intuitively, when we
apply such a timing function to a forwards-filling animation, we expect
it to produce an [=output progress value=] of 1 as the animation fills
forwards.
A similar situation arises for a step timing function with a [=step
position=] of <a value for="steps()">end</a> when applied to an animation
during its delay phase.
</div>
1. The [=output progress value=] is <code><var>current step</var>
/ [=steps=]</code>.
<div class=example>
As an example of how the [=before flag=] affects the behavior of this function,
consider an animation with a [=step timing function=] whose [=step
position=] is <a value for="steps()">start</a> and which has a positive
delay and backwards fill.
For example, using CSS animation:
<pre class='lang-css'>
animation: moveRight 5s 1s steps(5, start);
</pre>
During the delay phase, the [=input progress value=] will be zero but if the
[=before flag=] is set to indicate that the animation has yet to reach its
animation interval, the timing function will produce zero as its [=output
progress value=], i.e. the bottom of the first step.
At the exact moment when the animation interval begins, the [=input progress
value=] will still be zero, but the [=before flag=] will not be set and hence
the result of the timing function will correspond to the top of the first step.
</div>
The syntax for specifying a step timing function is as follows:
<div class="prod"><dfn type><step-timing-function></dfn> =
''step-start'' | ''step-end'' |
<span class="atom"><a lt="steps()" function>steps</a>(<<integer>>[,
[ ''start'' | ''end'' ] ]?)</span></div>
The meaning of each value is as follows:
<dl dfn-type=value dfn-for="step-timing-function, <step-timing-function>">
: <dfn>step-start</dfn>
:: Equivalent to steps(1, start);
: <dfn>step-end</dfn>
:: Equivalent to steps(1, end);
: <dfn function lt="steps()">steps(<integer>[, [ start | end ] ]?)</dfn>
:: Specifies a <a>step timing function</a>.
The first parameter specifies the number of intervals in the function.
It must be a positive integer greater than 0.
The second parameter, which is optional, is
either the value <dfn value for="steps()">start</dfn> or <dfn value
for="steps()">end</dfn>, and specifies the [=step position=].
If the second parameter is omitted, it is given the value ''end''.
</dl>
Frames timing functions: ''frames()'' {#frames-timing-functions}
----------------------------------------------------------------
A <dfn>frames timing function</dfn> is a type of <a>timing function</a>
that divides the input time into a specified number of intervals of equal
length, each of which is associated with an <a>output progress value</a> of
increasing value.
The difference between a [=frames timing function=] and a [=step timing
function=] is that a frames timing function returns the [=output progress
values=] 0 and 1 for an equal portion of the [=input progress values=] in
the range [0, 1].
This makes it suitable, for example, for using in animation loops where the
animation should display the first and last frame of the animation for an equal
amount of time as each other frame during each loop.
Some example frames timing functions are illustrated below.
<figure>
<img src="frames-timing-func-examples.svg" width="500"
alt="Example frames timing functions.">
<figcaption>
Example frames timing functions.
In each case the domain is the input progress whilst the range
represents the output progress produced by the function.
</figcaption>
</figure>
A [=frames timing function=] is defined by an integral number of
<dfn>frames</dfn> greater than one.
As with [=step timing functions=], at the exact point where a step occurs the
result of the function is conceptually the top of the step.
The [=output progress value=] is calculated from the [=input progress value=]
as follows:
1. Calculate the <var>current frame</var> as <code>floor([=input progress
value=] × [=frames=])</code>.
1. Let the initial [=output progress value=] be <code><var>current frame</var>
/ ([=frames=] - 1)</code>.
1. If [=input progress value=] ≤ 1 and [=output progress value=] > 1,
let [=output progress value=] be 1.
The syntax for specifying a frames timing function is as follows:
<div class="prod"><dfn type><frames-timing-function></dfn> =
<span class="atom"><dfn lt="frames()" function>frames(<<integer>>)</dfn></span></div>
The parameter to the function specifies the number of [=frames=].
It must be a positive integer greater than 1.
Serialization {#serializing-a-timing-function}
-------------
Timing functions are serialized using the common serialization patterns
defined in [[CSSOM]] with the following additional requirements:
* The keyword values ''ease'', ''linear'', ''ease-in'', ''ease-out'',
and ''ease-in-out'' are serialized as-is, that is, they are
<em>not</em> converted to the equivalent ''cubic-bezier()''
function before serializing.
* Step timing functions, whether they are specified using the
''steps()'' function or either of the ''step-start'' or ''step-end''
keywords, are serialized as follows:
1. If the [=step position=] is ''end'', serialize
as <a lt="steps()" function>steps(<integer>)</a>.
2. Otherwise, serialize as <a lt="steps()"
function>steps(<integer>, start)</a>.
Acknowledgements {#acknowledgements}
================
This specification is based on the <a
href="https://www.w3.org/TR/css3-transitions/">CSS Transitions</a> specification
edited by L. David Baron, Dean Jackson, David Hyatt, and Chris Marrin.
The editors would also like to thank Douglas Stockwell, Steve Block, Tab Atkins,
Rachel Nabors, Martin Pitt, and the <a
href="https://damp-lake-50659.herokuapp.com/">Animation at Work</a> slack
community for their feedback and contributions.