forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.bs
333 lines (256 loc) · 12.6 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
<h1>CSS Timing Functions Level 1</h1>
<pre class=metadata>
Status: ED
Work Status: Refining
Shortname: css-timing
Level: 1
Group: csswg
ED: https://drafts.csswg.org/css-timing/
Editor: Brian Birtles 43194, Mozilla https://www.mozilla.org, bbirtles@mozilla.com
Editor: Dean Jackson, Apple Inc https://www.apple.com/, dino@apple.com
Editor: Matt Rakow, Microsoft
Editor: Shane Stephens 47691, Google Inc, shans@google.com
Repository: w3c/csswg-drafts
!Issue Tracking: <a href="https://github.com/w3c/csswg-drafts/labels/css-timing-1">GitHub</a>
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 three types of timing functions whose definitions
follow.
The linear timing function {#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 for=single-timing-function>''linear''</dfn> keyword.
Cubic Bézier timing functions {#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-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 duration.
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. 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>
The <single-timing-function> production {#single-timing-function-production}
=============================================
The syntax for specifying a [=timing function=] is as follows:
<div class="prod"><dfn type><single-timing-function></dfn> =
''linear'' |
<<cubic-bezier-timing-function>> |
<<step-timing-function>></div>
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>.