8000 csswg-drafts/css-transitions/Overview.bs at 21f7b960d89c6845561246b202ab218fd34e1b4b · xfq/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
1719 lines (1625 loc) · 74.9 KB

File metadata and controls

1719 lines (1625 loc) · 74.9 KB
<h1>CSS Transitions</h1>
<style type="text/css">
table.animatable-properties {
border-collapse: collapse;
}
table.animatable-properties td {
padding: 0.2em 1em;
border: 1px solid black;
}
div.prod { margin: 1em 2em; }
</style>
<pre class="metadata">
Status: ED
Work Status: Refining
ED: http://dev.w3.org/csswg/css-transitions/
Shortname: css-transitions
Group: csswg
Level: 1
TR: http://www.w3.org/TR/css3-transitions/
Previous version: http://www.w3.org/TR/2013/WD-css3-transitions-20131119/
ED: http://dev.w3.org/csswg/css-transitions/
Editor: L. David Baron, Mozilla, http://dbaron.org/
Editor: Dean Jackson, Apple Inc, dino@apple.com
Editor: David Hyatt, Apple Inc, hyatt@apple.com
Editor: Chris Marrin, Apple Inc, cmarrin@apple.com
Issue Tracking: Bugzilla bugs for this level https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&amp;product=CSS&amp;component=Transitions&amp;resolution=---&amp;status_whiteboard=defer%20to%20level%202&amp;status_whiteboard_type=notregexp
Issue Tracking: Bugzilla bugs for all levels https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&amp;product=CSS&amp;component=Transitions&amp;resolution=---
Abstract: CSS Transitions allows property changes in CSS values to occur smoothly over a specified duration.
Status Text: <strong>This document</strong> is expected to be relatively close to last call. While some issues raised have yet to be addressed, new features are extremely unlikely to be considered for this level. <p>The following behaviors are at risk: <ul><li><a href="#discrete-interpolation-at-risk">Interpolation in steps of property types that cannot be interpolated</a></li></ul>
Ignored Terms: float
</pre>
<!-- FIXME: font-size and font-weight link defaults don't work -->
<pre class="link-defaults">
spec:css21; type:property;
text:top
text:right
text:bottom
text:left
text:margin-top
text:margin-right
text:margin-bottom
text:margin-left
text:padding-top
text:padding-right
text:padding-bottom
text:padding-left
text:border-top-color
text:border-right-color
text:border-bottom-color
text:border-left-color
text:border-top-width
text:border-right-width
text:border-bottom-width
text:border-left-width
text:background-color
text:background-position
text:border-spacing
text:width
text:height
text:min-width
text:min-height
text:max-width
text:max-height
text:clip
text:letter-spacing
text:line-height
text:outline-color
text:outline-width
text:text-indent
text:font-size
text:font-weight
text:vertical-align
text:visibility
text:word-spacing
text:z-index
spec:css-color-3;
type:property;
text:color
text:opacity
type:value
text:green
text:blue
text:transparent
spec:css-values-3; type:type; text:<time>
</pre>
<!-- FIXME: These overrides aren't great for dev/TR switching -->
<pre class="anchors">
url: http://dev.w3.org/csswg/css-backgrounds-3/#shadow-inset; type: value; for: shadow; text: inset;
url: http://www.w3.org/TR/CSS21/visufx.html#propdef-visibility; type: value; for: visibility; text: visible;
urlPrefix: http://dev.w3.org/csswg/css-color-3/; type: value;
text: transparent
text: blue
text: green
url: http://w3c.github.io/dom/#constructing-events; type: dfn; text: event constructor;
url: https://html.spec.whatwg.org/multipage/infrastructure.html#concept-event-dispatch; type: dfn; text: dispatch;
</pre>
</dl>
<h2 id="introduction">Introduction</h2>
<p><em>This section is not normative.</em>
<p>
This document introduces new CSS features to enable <em>implicit transitions</em>, which describe how CSS properties can be made to change smoothly from one value to another over a given duration.
</p>
<h2 id="transitions"><span id="transitions-">Transitions</span></h2>
<p>
Normally when the value of a CSS property changes, the rendered result is instantly updated, with the affected elements immediately changing from the old property value to the new property value. This section describes a way to specify transitions using new CSS properties. These properties are used to animate smoothly from the old state to the new state over time.
</p>
<p>
For example, suppose that transitions of one second have been defined on the 'left' and
'background-color' properties. The following diagram illustrates the effect of updating those properties on an element, in this case moving it to the right and changing the background from red to blue. This assumes other transition parameters still have their default values.
</p>
<div class="figure">
<img src="transition1.png" alt="">
</div>
<p class="caption">
Transitions of 'left' and 'background-color'
</p>
<p>
Transitions are a presentational effect. The <a>computed value</a> of a property transitions over time from the old value to the new value. Therefore if a script queries the <a>computed value</a> of a property (or other data depending on it) as it is transitioning, it will see an intermediate value that represents the current animated value of the property.
</p>
<p>
Only animatable CSS properties can be transitioned. See the table at the end of this document for a list
of properties that are animatable.
</p>
<p>
The transition for a property is defined using a number of new properties. For example:
</p>
<div class="example">
<p style="display:none">
Example(s):
</p>
<pre>
div {
transition-property: opacity;
transition-duration: 2s;
}
</pre>The above example defines a transition on the 'opacity' property that, when a new value is assigned to it, will cause a smooth change between the old value and the new value over a period of two seconds.
</div>
<p>
Each of the transition properties accepts a comma-separated list, allowing multiple transitions to be defined, each acting on a different property. In this case, the individual transitions take their parameters from the same index in all the lists. For example:
</p>
<div class="example">
<p style="display:none">
Example(s):
</p>
<pre>
div {
transition-property: opacity, left;
transition-duration: 2s, 4s;
}
</pre>This will cause the 'opacity' property to transition over a period of two seconds and the left property to transition over a period of four seconds.
</div>
<p id="list-matching">
In the case where the lists of values in transition properties
do not have the same length, the length of the
'transition-property' list determines the number of items in
each list examined when starting transitions. The lists are
matched up from the first value: excess values at the end are
not used. If one of the other properties doesn't have enough
comma-separated values to match the number of values of
'transition-property', the UA must calculate its used value by
repeating the list of values until there are enough. This
truncation or repetition does not affect the computed value.
<span class="note">
Note: This is analogous to the behavior of the 'background-*'
properties, with 'background-image' analogous to
'transition-property'.
</span>
</p>
<div class="example">
<p style="display:none">
Example(s):
</p>
<pre>
div {
transition-property: opacity, left, top, width;
transition-duration: 2s, 1s;
}
</pre>The above example defines a transition on the 'opacity' property of 2 seconds duration, a
transition on the 'left' property of 1
second duration, a transition on the 'top' property of 2 seconds duration and a
transition on the 'width' property of 1
second duration.
</div>
<p>
While authors can use transitions to create dynamically changing content,
dynamically changing content can lead to seizures in some users.
For information on how to avoid content that can lead to seizures, see
<a href="http://www.w3.org/TR/WCAG20/#seizure">Guideline 2.3:
Seizures:
Do not design content in a way that is known to cause seizures</a>
([[WCAG20]]).
</p>
<!-- ======================================================================================================= -->
<h3 id="transition-property-property"><span id="the-transition-property-property-">
The 'transition-property' Property
</span></h3>
<p>
The 'transition-property' property specifies the name of the CSS property to which the transition is applied.
</p>
<pre class="propdef">
Name: transition-property
Value: ''transition-property/none'' | <<single-transition-property>>#
Initial: ''transition-property/all''
Applies to: all elements, ::before and ::after pseudo elements
Inherited: no
Animatable: no
Percentages: N/A
Media: visual
Computed value: Same as specified value.
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
</pre>
<div class="prod">
<dfn type id="single-transition-property">&lt;single-transition-property&gt;</dfn> = ''transition-property/all'' | <<custom-ident>>;
</div>
<p>
A value of
<dfn value for="transition-property">none</dfn>
means that no property will transition.
Otherwise, a list of properties to be transitioned, or the
keyword <dfn value for="transition-property">all</dfn>
which indicates that all properties are to be
transitioned, is given.
</p>
<p>
If one of the identifiers listed is not a recognized property
name or is not an animatable property, the implementation must
still start transitions on the animatable properties in the
list using the duration, delay, and timing function at their
respective indices in the lists for 'transition-duration',
'transition-delay', and 'transition-timing-function'. In other
words, unrecognized or non-animatable properties must be kept in
the list to preserve the matching of indices.
</p>
<p>
The <<custom-ident>> production in <<single-transition-property>>
also excludes the keyword ''transition-property/none'',
in addition to the keywords always excluded from <<custom-ident>>.
This means that
''transition-property/none'', ''inherit'', and ''initial'' are not
permitted as items within a list of more that one identifier;
any list that uses them is syntactically invalid.
</p>
<p>
For the keyword ''transition-property/all'',
or if one of the identifiers listed is a
shorthand property, implementations must start transitions for
any of its longhand sub-properties that are animatable (or, for
''transition-property/all'', all animatable properties), using the duration, delay,
and timing function at the index corresponding to the shorthand.
</p>
<p>
If a property is specified multiple times in the value of
'transition-property' (either on its own, via a shorthand that
contains it, or via the ''transition-property/all'' value), then the transition that
starts uses the duration, delay, and timing function at the
index corresponding to the <em>last</em> item in the value of
'transition-property' that calls for animating that property.
</p>
<p class="note">
Note: The ''transition-property/all'' value and 'all' shorthand
property work in similar ways, so the
''transition-property/all'' value is just like a shorthand that
covers all properties.
</p>
<!-- ======================================================================================================= -->
<h3 id="transition-duration-property"><span id="the-transition-duration-property-">
The 'transition-duration' Property
</span></h3>
<p>
The 'transition-duration' property defines the length of time that a transition takes.
</p>
<pre class="propdef">
Name: transition-duration
Value: <<time>>#
Initial: ''0s''
Applies to: all elements, ::before and ::after pseudo elements
Inherited: no
Animatable: no
Percentages: N/A
Media: interactive
Computed value: Same as specified value.
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
</pre>
<p>
This property specifies how long the transition from the old value to the new value should take. By default the value is ''0s'', meaning that the transition is immediate (i.e. there will be no animation). A negative value for 'transition-duration' renders the declaration invalid.
</p>
<!-- =======================================================================================================
-->
<h3 id="transition-timing-function-property"><span id="transition-timing-function_tag">
The 'transition-timing-function' Property
</span></h3>
<p>
The 'transition-timing-function' property
describes how the intermediate values used during a transition will be
calculated. It allows for a transition to change speed over its
duration. These effects are commonly called <em>easing</em> functions.
In either case, a mathematical function that provides a smooth curve is
used.
</p>
<p>
Timing functions are either defined as a stepping function or
a <a
href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic
B&eacute;zier curve</a>.
The timing function takes as its input
the current elapsed percentage of the transition duration
and outputs the percentage of the way the transition is
from its start value to its end value.
How this output is used is defined by
the <a href="#animatable-types">interpolation rules</a>
for the value type.
</p>
<p>
A <a href="http://en.wikipedia.org/wiki/Step_function">stepping</a>
function is defined by a number that divides the domain of operation
into equally sized intervals. Each subsequent interval is a equal step
closer to the goal state. The function also specifies whether the
change in output percentage happens at the start or end of the
interval (in other words, if 0% on the input percentage is the point
of initial change).
</p>
<div class="figure">
<img src="step.png" alt="The step timing function splits
the function domain into a number of disjoint straight line
segments. steps(1, start) is a function whose
output value is 1 for all input values. steps(1, end) is a function whose
output value is 0 for all input values less than 1, and output
is 1 for the input value of 1. steps(3, start) is a function that
divides the input domain into three segments, each 1/3 in length,
and 1/3 above the previous segment, with the first segment starting
at 1/3. steps(3, end) is a function that
divides the input domain into three segments, each 1/3 in length,
and 1/3 above the previous segment, with the first segment starting
at 0.">
</div>
<p class="caption">
Step timing functions
</p>
<p>
A <a
href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic
B&eacute;zier curve</a> is defined by four control points, P<sub>0</sub>
through P<sub>3</sub> (see Figure 1). P<sub>0</sub> and P<sub>3</sub>
are always set to (0,0) and (1,1). The 'transition-timing-function' property is used
to specify the values for points P<sub>1</sub> and P<sub>2</sub>. These
can be set to preset values using the keywords listed below, or can be
set to specific values using the ''cubic-bezier()'' function.
In the ''cubic-bezier()'' function, P<sub>1</sub> and
P<sub>2</sub> are each specified by both an X and Y value.
</p>
<div class="figure">
<img src="TimingFunction.png" alt="The B&eacute;zier timing function is a
smooth curve from point P0 = (0,0) to point P3 = (1,1). The
length and orientation of the line segment P0-P1 determines
the tangent and the curvature of the curve at P0 and the
line segment P2-P3 does the same at P3.">
</div>
<p class="caption">
B&eacute;zier Timing Function Control Points
</p>
<pre class="propdef">
Name: transition-timing-function
Value: <<single-transition-timing-function>>#
Initial: ''transition-timing-function/ease''
Applies to: all elements, ::before and ::after pseudo elements
Inherited: no
Animatable: no
Percentages: N/A
Media: interactive
Computed value: Same as specified value.
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
</pre>
<div class="prod">
<dfn type id="single-transition-timing-function">&lt;single-transition-timing-function&gt;</dfn> = ''ease'' | ''linear'' | ''ease-in'' | ''ease-out'' | ''ease-in-out'' | ''step-start'' | ''step-end'' | <a lt="steps()" function>steps</a>(<<integer>>[, [ ''start'' | ''end'' ] ]?) | <a lt="cubic-bezier()" function>cubic-bezier</a>(<<number>>, <<number>>, <<number>>, <<number>>)
</div>
<p>
The timing functions have the following definitions.
</p>
<dl dfn-type="value" dfn-for="transition-timing-function, <single-transition-timing-function>">
<dt><dfn>ease</dfn></dt>
<dd>
The ease function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.25, 0.1, 0.25, 1)</a>.
</dd>
<dt><dfn>linear</dfn></dt>
<dd>
The linear function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0, 0, 1, 1)</a>.
</dd>
<dt><dfn>ease-in</dfn></dt>
<dd>
The ease-in function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.42, 0, 1, 1)</a>.
</dd>
<dt><dfn>ease-out</dfn></dt>
<dd>
The ease-out function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0, 0, 0.58, 1)</a>.
</dd>
<dt><dfn>ease-in-out</dfn></dt>
<dd>
The ease-in-out function is equivalent to <a lt="cubic-bezier()" function>cubic-bezier(0.42, 0, 0.58, 1)</a>.
</dd>
<dt><dfn>step-start</dfn></dt>
<dd>
The step-start function is equivalent to <a lt="steps()" function>steps(1, start)</a>.
</dd>
<dt><dfn>step-end</dfn></dt>
<dd>
The step-end function is equivalent to <a lt="steps()" function>steps(1, end)</a>.
</dd>
<dt><dfn function lt="steps()">steps(<<integer>>[, [ start | end ] ]?)</dfn></dt>
<dd>
Specifies a stepping function, described above, taking two
parameters. 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 point
at which the change of values occur within the interval.
If the second parameter is omitted, it is given the value ''end''.
</dd>
<dt><dfn function lt="cubic-bezier()">cubic-bezier(<<number>>, <<number>>, <<number>>, <<number>>)</dfn></dt>
<dd>
Specifies a <a
href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">cubic-bezier
curve</a>. The four values specify points P<sub>1</sub> and
P<sub>2</sub> of the curve as (x1, y1, x2, y2). Both x values must be
in the range [0, 1] or the definition is invalid. The y values can
exceed this range.
</dd>
</dl><!-- ======================================================================================================= -->
<h3 id="transition-delay-property"><span id="the-transition-delay-property-">
The 'transition-delay' Property
</span></h3>
<p>
The 'transition-delay' property defines when the transition will start. It allows a transition to begin execution some some period of time from when it is applied. A 'transition-delay' value of ''0s'' means the transition will execute as soon as the property is changed. Otherwise, the value specifies an offset from the moment the property is changed, and the transition will delay execution by that offset.
</p>
<p>
If the value for 'transition-delay' is a negative time offset then the transition will execute the moment the property is changed, but will appear to have begun execution at the specified offset. That is, the transition will appear to begin part-way through its play cycle. In the case where a transition has implied starting values and a negative 'transition-delay', the starting values are taken from the moment the property is changed.
</p>
<pre class="propdef">
Name: transition-delay
Value: <<time>>#
Initial: ''0s''
Applies to: all elements, ::before and ::after pseudo elements
Inherited: no
Animatable: no
Percentages: N/A
Media: interactive
Computed value: Same as specified value.
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
</pre><!-- ======================================================================================================= -->
<h3 id="transition-shorthand-property"><span id="the-transition-shorthand-property-">
The 'transition' Shorthand Property
</span></h3>
<p>
The 'transition' shorthand property combines the four properties described above into a single property.
</p>
<pre class="propdef">
Name: transition
Value: <<single-transition>>#
Initial: see individual properties
Applies to: all elements, ::before and ::after pseudo elements
Inherited: no
Animatable: no
Percentages: N/A
Media: interactive
Computed value: see individual properties
Canonical order: <abbr title="follows order of property value definition">per grammar</abbr>
</pre>
<div class="prod">
<dfn type id="single-transition">&lt;single-transition&gt;</dfn> = [ ''none'' | <<single-transition-property>> ] || <<time>> || <<single-transition-timing-function>> || <<time>>
</div>
<p>
Note that order is important within the items in this property:
the first value that can be parsed as a time is assigned to the
transition-duration,
and the second value that can be parsed as a time is assigned to
transition-delay.
</p>
<p>
If there is mo 6CC9 re than one <<single-transition>> in the shorthand,
and any of the transitions has
''none'' as the <<single-transition-property>>,
then the declaration is invalid.
</p>
<h2 id="starting">
Starting of transitions
</h2>
<p>
Implementations must maintain a set of
<dfn export lt="running transition">running transitions</dfn>,
each of which applies to a specific element and non-shorthand
property. Each of these transitions also has a
<dfn export for="transition">start time</dfn>, <dfn export for="transition">end time</dfn>,
<dfn export for="transition">start value</dfn>, <dfn export for="transition">end value</dfn>,
<dfn export for="transition">reversing-adjusted start value</dfn>, and <dfn export for="transition">reversing shortening factor</dfn>.
Transitions are added to this set as described in this section,
and are removed from this set
when they <a>complete</a>
or when implementations are required to <dfn export for="transition">cancel</dfn> them.
<span class="note">
For the rationale behind the <a>reversing-adjusted start value</a>
and <a>reversing shortening factor</a>, see [[#reversing]].
</span>
</p>
<p>
Implementations must also maintain a set of
<dfn export lt="completed transition">completed transitions</dfn>,
each of which
(like <a>running transitions</a>)
applies to a specific element and non-shorthand property.
<span class="note">
This specification maintains the invariant that
there is never both a <a>running transition</a> and
a <a>completed transition</a> for the same property and element.
</span>
</p>
<p>
If an element is no longer in the document,
implementations must remove transitions on it
from the <a>running transitions</a> and the
<a>completed transitions</a>.
</p>
<div class="note">
<p>
This set of completed transitions
needs to be maintained
in order to prevent
transitions from repeating themselves in certain cases,
i.e., to maintain the invariant
that this specification tries to maintain
that unrelated style changes do not trigger transitions.
</p>
<p class="example">
An example where maintaining the set of completed transitions
is necessary would be a transition on
an inherited property,
where the parent specifies a transition of that property for
a longer duration (say, ''transition: 4s text-indent'')
and a child element that inherits the parent's value specifies
a transition of the same property for a shorter duration
(say, ''transition: 1s text-indent'').
Without the maintenance of this set of completed transitions,
implementations could start additional transitions on the child
after the initial 1 second transition on the child completes.
</p>
</div>
<p>
Various things can cause the <a>computed values</a> of properties
on an element to change.
These include
insertion and removal of elements from the document tree
(which both changes whether those elements have <a>computed values</a> and
can change the styles of other elements through selector matching),
changes to the document tree that cause
changes to which selectors match elements,
changes to style sheets or style attributes,
and other things.
This specification does not define when <a>computed values</a> are updated,
beyond saying that implementations must not
use, present, or display something resulting from the CSS
cascading, value computation, and inheritance process [[!CSS3CASCADE]]
without updating the <a>computed value</a>
(which means merely that implementations cannot avoid
meeting requirements of this specification
by claiming not to have updated the <a>computed value</a>
as part of handling a style change).
However,
when an implementation updates the <a>computed value</a> of a
property on an element
to reflect one of these changes,
or computes the <a>computed value</a> of a property on an element
newly added to the document,
8096 it must update the <a>computed value</a>
for all properties and elements to reflect all
of these changes at the same time
(or at least it must be undetectable that it was done at a
different time).
This processing of a set of simultaneous style changes is called a
<dfn export>style change event</dfn>.
(Implementations typically have a <a>style change event</a> to
correspond with their desired screen refresh rate,
and when up-to-date computed style or layout information is needed
for a script API that depends on it.)
</p>
<p>
Since this specification does not define
when a <a>style change event</a> occurs,
and thus what changes to computed values are considered simultaneous,
authors should be aware that changing any of the transition
properties a small amount of time after making a change that
might transition can result in behavior that varies between
implementations, since the changes might be considered
simultaneous in some implementations but not others.
</p>
<p>
When a <a>style change event</a> occurs,
implementations must start transitions based on
the <a>computed values</a> that changed in that event.
If an element is not in the document during that
style change even or was not in the document during
the previous style change event,
then transitions are not started for that element
in that style change event.
Otherwise,
define the <dfn export>before-change style</dfn> as
the <a>computed values</a> of all properties on the element as of
the previous <a>style change event</a>,
except with any styles derived from declarative
animations such as CSS Transitions, CSS Animations
([[CSS3-ANIMATIONS]]),
and SMIL Animations ([[SMIL-ANIMATION]], [[SVG11]])
updated to the current time.
Likewise, define the <dfn export>after-change style</dfn> as
the <a>computed values</a> of all properties
on the element based on the information
known at the start of that <a>style change event</a>,
but excluding any styles from CSS Transitions in the computation,
and inheriting from
the <a>after-change style</a> of the parent.
</p>
<div class="note">
<p>
Note that this definition of the <a>after-change style</a>
means that a single change
can start a transition on the same property
on both an ancestor element and its descendant element.
This can happen when a property change is inherited
from one element with 'transition-*' properties
that say to animate the changing property
to another element with 'transition-*' properties
that also say to animate the changing property.
</p>
<p>
When this happens, both transitions will run,
and the transition on the descendant will override
the transition on the ancestor
because of the normal
CSS cascading and inheritance rules ([[CSS3CASCADE]]).
</p>
<p>
If the transition on the descendant completes before
the transition on the ancestor,
the descendant will then resume inheriting
the (still transitioning) value from its parent.
This effect is likely not a desirable effect,
but it is essentially doing what the author asked for.
</p>
</div>
<p>
For each element with a <a>before-change style</a> and
an <a>after-change style</a>,
and each property (other than shorthands),
define the <dfn export>matching transition-property value</dfn> as
the last value in the
'transition-property' in the element's <a>after-change style</a>
that matches the property,
as described in
[[#transition-property-property]].
If there is such a value, then corresponding to it, there is
a <dfn export>matching transition duration</dfn>,
a <dfn export>matching transition delay</dfn>, and
a <dfn export>matching transition timing function</dfn>
in the values in the <a>after-change style</a> of
'transition-duration', 'transition-delay', and 'transition-timing-function'
(see <a href="#list-matching">the rules on matching lists</a>).
Define the <dfn export for="transition">combined duration</dfn> of the transition
as the sum of max(<a>matching transition duration</a>, ''0s'') and
the <a>matching transition delay</a>.
For each element and property, the implementation must act
as follows:
</p>
<ol>
<li>
If all of the following are true:
<ul>
<li>
the element does not have
a <a>running transition</a> for the property,
</li>
<li>
the <a>before-change style</a> is different from
and can be interpolated with
the <a>after-change style</a> for that property,
</li>
<li>
the element does not have a <a>completed transition</a>
for the property
or the <a>end value</a> of the <a>completed transition</a>
is different from the <a>after-change style</a> for the property,
</li>
<li>
there is a <a>matching transition-property value</a>, and
</li>
<li>
the <a>combined duration</a> is greater than ''0s'',
</li>
</ul>
then implementations must
remove the <a>completed transition</a> (if present) from the set
of completed transitions and
start a transition whose:
<ul>
<li>
<a>start time</a> is
the time of the <a>style change event</a> plus
the <a>matching transition delay</a>,
</li>
<li>
<a>end time</a> is
the <a>start time</a> plus
the <a>matching transition duration</a>,
</li>
<li>
<a>start value</a> is
the value of the transitioning property
in the <a>before-change style</a>,
</li>
<li>
<a>end value</a> is
the value of the transitioning property
in the <a>after-change style</a>,
</li>
<li>
<a>reversing-adjusted start value</a> is the same as
the <a>start value</a>, and
<li>
<a>reversing shortening factor</a> is 1.
</li>
</ul>
</li>
<li>
Otherwise,
if the element has a <a>completed transition</a> for the property
and the <a>end value</a> of the <a>completed transition</a>
is different from the <a>after-change style</a> for the property,
then implementations must
remove the <a>completed transition</a> from the set of
<a>completed transitions</a>.
</li>
<li>
If the element has a <a>running transition</a> or
<a>completed transition</a> for the property,
and there is <strong>not</strong>
a <a>matching transition-property value</a>,
then implementations must
<a>cancel</a> the <a>running transition</a>
or remove the <a>completed transition</a> from the set of
<a>completed transitions</a>.
</li>
<li>
If the element has a <a>running transition</a> for the property,
there is a <a>matching transition-property value</a>,
and the <a>end value</a> of the <a>running transition</a> is
<strong>not</strong> equal to the value of the property in the
<a>after-change style</a>, then:
<ol>
<li>
If the <a>current value</a> of the property
in the <a>running transition</a>
is equal to
the value of the property in the <a>after-change style</a>,
or if these two values cannot be interpolated,
then implementations must
<a>cancel</a> the <a>running transition</a>.
</li>
<li>
Otherwise, if the <a>combined duration</a> is
less than or equal to ''0s'',
or if the
<a>current value</a> of the property in the <a>running transition</a>
cannot be interpolated with
the value of the property in the <a>after-change style</a>,
then implementations must
<a>cancel</a> the <a>running transition</a>.
</li>
<li>
Otherwise, if the <a>reversing-adjusted start value</a>
of the <a>running transition</a> is the same as the value of
the property in the <a>after-change style</a>
<span class="note">(see the
<a href="#reversing">section on reversing of
transitions</a> for why these case exists)</span>,
implementations must
<a>cancel</a> the <a>running transition</a> and
start a new transition whose:
<ul>
<li>
<a>reversing-adjusted start value</a> is
the <a>end value</a> of the
<a>running transition</a>
<span class="note">(Note: This represents the logical start state of
the transition, and allows some calculations to ignore that
the transition started before that state was reached, which
in turn allows repeated reversals of the same transition to
work correctly),</span>
<li>
<a>reversing shortening factor</a>
is the absolute value, clamped to the range [0, 1],
of the sum of:
<ol>
<li>the output of the timing function of the old transition
at the time of the <a>style change event</a>,
times the <a>reversing shortening factor</a> of the
old transition</li>
<li>1 minus the <a>reversing shortening factor</a> of
the old transition.</li>
</ol>
<span class="note">Note: This represents the portion of the
space between the <a>reversing-adjusted start value</a>
and the <a>end value</a> that the old transition has
traversed (in amounts of the value, not time), except with the
absolute value and clamping to handle timing functions that
have y1 or y2 outside the range [0, 1].</span>
</li>
<li>
<a>start time</a> is
the time of the <a>style change event</a> plus:
<ol>
<li>if the <a>matching transition delay</a>
is nonnegative,
the <a>matching transition delay</a>, or
<li>if the <a>matching transition delay</a>
is negative,
the product of
the new transition's
<a>reversing shortening factor</a> and
the <a>matching transition delay</a>,
</ol>
</li>
<li>
<a>end time</a> is
the <a>start time</a> plus the product of
the <a>matching transition duration</a> and
the new transition's <a>reversing shortening factor</a>,
</li>
<li>
<a>start value</a> is
the <a>current value</a> of the property
in the <a>running transition</a>,
</li>
<li>
<a>end value</a> is
the value of the property
in the <a>after-change style</a>,
</li>
</ul>
</li>
<li>
Otherwise, implementations must
<a>cancel</a> the <a>running transition</a>
and start a new transition whose:
<ul>
<li>
<a>start time</a> is
the time of the <a>style change event</a> plus
the <a>matching transition delay</a>,
</li>
<li>
<a>end time</a> is
the <a>start time</a> plus
the <a>matching transition duration</a>,
</li>
<li>
<a>start value</a> is
the <a>current value</a> of the property
in the <a>running transition</a>,
</li>
<li>
<a>end value</a> is
the value of the property
in the <a>after-change style</a>,
</li>
<li>
<a>reversing-adjusted start value</a> is the same as
the <a>start value</a>, and
<li>
<a>reversing shortening factor</a> is 1.
</li>
</ul>
</li>
</ol>
</li>
</ol>
<div class="note">
<p>
Note that the above rules mean that
when the computed value of an animatable property changes,
the transitions that start are based on the
values of the 'transition-property', 'transition-duration',
'transition-timing-function', and 'transition-delay' properties
at the time the animatable property would first have its new
computed value.
This means that when one of these 'transition-*' properties
changes at the same time as
a property whose change might transition,
it is the <em>new</em> values of the 'transition-*' properties
that control the transition.
</p>
<div class="example" id="manual-reversing-example">
<p style="display:none">
Example(s):
</p>
<p>This provides a way for authors to specify different values
of the 'transition-*' properties for the &ldquo;forward&rdquo;
and &ldquo;reverse&rdquo; transitions,
when the transitions are between two states
(but see <a
href="#reversing">below</a> for special reversing behavior when
an <em>incomplete</em> transition is interrupted). Authors can
specify the value of 'transition-duration',
'transition-timing-function', or 'transition-delay' in the same
rule where they specify the value that triggers the transition,
or can change these properties at the same time as they change
the property that triggers the transition. Since it's the new
values of these 'transition-*' properties that affect the
transition, these values will be used for the transitions
<em>to</em> the associated transitioning values. For example:
</p>
<pre>
li {
transition: background-color linear 1s;
background: blue;
}
li:hover {
background-color: green;
transition-duration: 2s; /* applies to the transition *to* the :hover state */
}</pre>
<p>
When a list item with these style rules enters the :hover
state, the computed 'transition-duration' at the time that
'background-color' would have its new value (''green'') is ''2s'',
so the transition from ''blue'' to ''green'' takes 2 seconds.
However, when the list item leaves the :hover state, the
transition from ''green'' to ''blue'' takes 1 second.
</p>
</div>
</div>
<p class="note">
Note that once the transition of a property has started
(including being in its delay phase),
it continues running based on
the original timing function, duration, and
delay, even if the 'transition-timing-function',
'transition-duration', or 'transition-delay' property changes
before the transition is complete. However, if the
'transition-property' property changes such that the transition
would not have started, the transition stops (and the
property immediately changes to its final value).
</p>
<p class="note">
Note that above rules mean that
transitions do not start when the computed
value of a property changes as a result of declarative animation
(as opposed to scripted animation).
This happens because the before-change style includes up-to-date
style for declarative animations.
</p>
<h3 id="reversing">