The Spec Says…
“If a property is not specified for a
keyframe, or is specified but invalid, the
animation of that property proceeds as if
that keyframe did not exist.”
Animations
normal
alternate
reverse
alternate-reverse
animation-direction:
Slide 43
Slide 43 text
One Direction
Slide 44
Slide 44 text
Animations
If animation-direction has a value of
reverse or alternate-reverse, the
value of animation-timing-function is
also reversed.
e.g. ease-in becomes ease-out.
Slide 45
Slide 45 text
Animations
none
backwards
forwards
both
animation-fill-mode:
Slide 46
Slide 46 text
Fill Mode
backwards will apply the properties in
the from keyframe before the
animation begins.
forwards will apply the properties in
the to keyframe when the animation
ends.
both will apply the properties in the
from keyframe before the animation
begins, and the properties in the to
keyframe when the animation ends.
Slide 47
Slide 47 text
Fill Mode
div { animation: foo 1s 1s; }
animation-fill-mode: backwards;
animation-fill-mode: forwards;
animation-fill-mode: both;
Slide 48
Slide 48 text
Spec Violation
“When the animation-duration is 0s,
animation-fill-mode still applies.”
But no browser I’ve tested
complies with this.
Slide 49
Slide 49 text
Animations
running
paused
animation-play-state:
Slide 50
Slide 50 text
Multiple Animations
@keyframes one {
to { background-color: red; }
}
@keyframes two {
to {
background-color: blue;
width: 200px;
}
}
div { animation: two 1s, one 1s; }
Slide 51
Slide 51 text
Multiple Animations
div { animation:
foo 1s infinite,
bar 2s 1s alternate-reverse,
baz 500ms alternate infinite;
}
Good luck with that!
Slide 52
Slide 52 text
Rubbish
No @keyframes view
in dev tools. :(
LOL
Slide 53
Slide 53 text
Transitionable
The properties that can be
transitioned are generally those which
accept quantifiable values:
length, color, number, or percentage
http://thewebevolved.com/support/animation/properties/
Slide 54
Slide 54 text
Transitionable
The auto value isn’t quantifiable,
so can’t be animated to or from.
Values inside the calc() function
are, so can be.
Slide 55
Slide 55 text
Transitionable
The visibility property is a special
case: it toggles between hidden and
visible at the end* of the animation,
with no transition.
*or the beginning, depending on your parameters
Slide 56
Slide 56 text
Visibility
Slide 57
Slide 57 text
Transitionable
Some properties will be implicitly
transitioned - e.g. a transition on the
font-size property makes other
properties that have values relative to
it - line-height, margin, etc -
transition also.
The exception is IE10, where only
line-height will be transitioned.
Slide 58
Slide 58 text
Transitionable
You can transition properties
applied to the ::after and ::before
pseudo-elements*.
*except in Safari
Spec Violation
“Gradient[s]… must have the same type
(radial or linear) and same number of
stops in order to be animated.”
No browser I’ve tested
complies with this.
Slide 62
Slide 62 text
Transitionable
text { transition: 2s; }
svg:hover rect { fill: green; }
Slide 63
Slide 63 text
Events
transitionend*
*webkitTransitionEnd in Safari
el.addEventListener(
'transitionend',
fooBar
);
Slide 64
Slide 64 text
Events
el.addEventListener(
'transitionend',
function(e) {
var time = e.timeElapsed,
prop = e.propertyName;
});
Slide 65
Slide 65 text
TIL
When shorthand properties are
transitioned, the transitionend event
fires for all of the individual properties.
Except in Chrome and Safari, if you
explicitly state the shorthand property as
the value for transition-property.
Slide 66
Slide 66 text
TIL
Firefox doesn’t fire the transitionend
event when pseudo elements are
transitioned, and the event object doesn’t
contain the pseudoElement attribute.
Slide 67
Slide 67 text
TIL
When you use the all value for
transition-property, the implicit
transitions that fire the transitionend
event vary between browsers.
Slide 68
Slide 68 text
TIL
Firefox in particular fires on some quite
unexpected properties.
div { transition: color 1s; }
Events
el.addEventListener(
'transitionend',
function(e) {
var time = e.timeElapsed,
anim = e.animationName;
});
Slide 72
Slide 72 text
TIL
In Firefox, the animationstart event
doesn’t fire if the animation begins
before the DOMContentLoaded event.
Slide 73
Slide 73 text
Duh.
The animationend event doesn’t fire
when the animation-iteration property
has a value of infinite.
Slide 74
Slide 74 text
Spec Violation
“When the animation-duration is 0s,
animation-fill-mode still applies…
also, animation events are still fired.”
No browser I’ve tested does this.
Slide 75
Slide 75 text
Performance
“Use CSS keyframe animation or CSS
transitions, if at all possible. The
browser can optimize painting and
compositing bigtime here.”
http://paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/
Slide 76
Slide 76 text
Performance
Chrome uses graphics acceleration
automatically for transitioned elements, but
in Safari, especially for iOS, you may have
to force it:
div { -webkit-transform: rotateY(0deg); }
However…
http://blog.tumult.com/2013/02/28/transform-translate-vs-top-left/
Slide 77
Slide 77 text
Performance
… semi-opaque or transparent
elements may see little tangible
benefit from the rotateY hack - and it
could even reduce performance.
http://blog.tumult.com/2013/02/28/transform-translate-vs-top-left/
Slide 78
Slide 78 text
Obligatory
It depends.
Slide 79
Slide 79 text
No content
Slide 80
Slide 80 text
CSS3 v jQuery
http://thewebevolved.com/support/animation/properties/
Slide 81
Slide 81 text
Soft Skills
Animation is behaviour.
Slide 82
Slide 82 text
Time
“Animation can help to provide
context. It helps brains understand
how the information flows.”
https://medium.com/design-ux/926eb80d64e3
Slide 83
Slide 83 text
Time
Slide 84
Slide 84 text
Speed
Speed it all up. People aren’t on your
site to admire your animation skills
they’re there to achieve an aim.
The Future
var anim = el.animate({}, t);
var anim = el.animate({color:'red'}, 2);
https://dvcs.w3.org/hg/FXTF/raw-file/default/web-anim/index.html
Slide 93
Slide 93 text
The Future
var anim = new Animation(el, {color:'red'}, 2);
document.timeline.play(anim);
var anim = new Animation(
el,
{color:'red'},
{
iterationDuration: 3,
playbackRate: 2
}
);
Slide 94
Slide 94 text
The Future
var animA = new Animation(eA, {opacity:0}, 2),
animB = new Animation(eB, animA.effect, 4);