Choose your (web) animation adventure

A presentation at FullStack London in July 2018 in London, UK by Val Head

Slide 1

Slide 1

Choose Your Animation Adventure Val Head • @vlh Author of Designing Interface Animation Design Advocate, Adobe

Slide 2

Slide 2

Slide 3

Slide 3

You have encountered an interface that requires animation. What would you like to use? (1) CSS? (2) JavaScript? (3) SVG? (4) …?

Slide 4

Slide 4

Slide 5

Slide 5

CSS Key Frames Transitions

Slide 6

Slide 6

What CSS is great at: • Well-defined state transitions • Loading animations, looping animations • Animations on :hover, :focus and similar CSS

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

Slide 12

Slide 12

Pros: • No external library needed • Great potential for performance without much e ! ort • Keyframes are reusable
• Can adjust properties in media queries for responsive animation when needed CSS

Slide 13

Slide 13

Cons: • Access to limited events • Defined entirely ahead of time • Can’t separate transform properties* CSS

Slide 14

Slide 14

CSS + JS

!

Slide 15

Slide 15

Slide 16

Slide 16

Slide 17

Slide 17

CSS In Summary Where it shines: • Animated interactions with defined states • Simple interactive animations Biggest Pro: • Nearly e ! ortless performance • No additional requests

Slide 18

Slide 18

CSS is pretty great, but it might be 
 time to move to JavaScript if: • You’ll be chaining more than 3-ish animations in a sequence • The animation needs to change dynamically at runtime • Need to animate transform properties separately
• Physics or other complex easing structures are required

Slide 19

Slide 19

Vanilla Canvas Web GL react Libs Web Animation API JS

Slide 20

Slide 20

What javascript is great at: JS • Complex animated interactions • Narrative or immersive animation • Dynamic state transitions

Slide 21

Slide 21

Slide 22

Slide 22

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

Slide 26

Slide 26

requestAnimationFrame

Slide 27

Slide 27

Vanilla JS - requestAnimationFrame JS const moveCat = () !” { … currentValue = changeInValue * progress + startValue 
 cat.style.transform = translate3d(${currentValue}px, 0, 0)
… requestAnimationFrame(moveCat); } moveCat();

Slide 28

Slide 28

Vanilla JS - requestAnimationFrame JS const moveCat = () !” { … currentValue = changeInValue * progress + startValue 
 cat.style.transform = translate3d(${currentValue}px, 0, 0)
… requestAnimationFrame(moveCat); } moveCat();

Slide 29

Slide 29

Vanilla JS - requestAnimationFrame JS const moveCat = () !” { … currentValue = changeInValue * progress + startValue 


cat.style.transform = translate3d(${currentValue}px, 0, 0)
… requestAnimationFrame(moveCat); } moveCat();

Slide 30

Slide 30

Vanilla JS - requestAnimationFrame JS const moveCat = () !” { … currentValue = changeInValue * progress + startValue 
 cat.style.transform = translate3d(${currentValue}px, 0, 0)
… requestAnimationFrame(moveCat); } moveCat();

Slide 31

Slide 31

Slide 32

Slide 32

JS animation libraries

Slide 33

Slide 33

Comparing JavaScript animation libraries…

Slide 34

Slide 34

Slide 35

Slide 35

TweenMax.to( box , 1 , 
 { opacity:1, x:800 , ease:Power2.easeIn } 
 ); Velocity( box , 
 { opacity: 1, translateX:”+=800 “}, 
 { duration: 1000 , easing:”easeInQuad” }); anime({ targets: box ,

opacity:1, translateX: 800, 


duration: 1000,

easing: ‘easeInQuad’ 
 });

Slide 36

Slide 36

Slide 37

Slide 37

~9 - 29kb ~14.4kb ~4.7kb back to IE8* back to IE8 back to IE10 Docs + forums Docs + SO Docs drawSVG, morphSVG, Draggable drop-in replacement for jQuery very lightweight Some features and licensing 
 requires $ MIT license MIT license *These are not the only JS animation libraries out there.

Slide 38

Slide 38

JavaScript In Summary Where it shines: • Complex UI animation • Animation with dynamic states • Immersive animation Biggest Pro: • Lots of options for how to get it done • Can animate DOM, SVG, canvas

Slide 39

Slide 39

SVG

Slide 40

Slide 40

Slide 41

Slide 41

Slide 42

Slide 42

What SVG is great at: SVG • Animated illustrations
• Animated icons • Infographics and dataviz • Fluidly scaling, responsive animation

Slide 43

Slide 43

Slide 44

Slide 44

Slide 45

Slide 45

Slide 46

Slide 46

Slide 47

Slide 47

Slide 48

Slide 48

SMIL •

Tag-based animation within SVG • No IE or Edge support • Future in Chrome uncertain “

$ CSS • Transitions and keyframe animations can be applied to SVG elements • Limited number of properties are exposed to CSS • Transforms on child elements not supported in IE* JS • Can access/animate native SVG properties • Can do motion along path, shape morphing and more just like SMIL

Slide 49

Slide 49

Slide 50

Slide 50

airbnb.design/lottie/

Slide 51

Slide 51

lottiefiles.com

Slide 52

Slide 52

github.com/airbnb/lottie-web

Slide 53

Slide 53

SVG In Summary Where it shines: • Animated illustrations & infographics • Shape morphing • Motion along a path Biggest Pro: • Responsive by nature • Potential for tiny file sizes

Slide 54

Slide 54

PERFORMANCE

Slide 55

Slide 55

size

  • transform: scale() position
  • transform: translate() rotation
  • transform: rotate() opacity

Slide 56

Slide 56

composite paint layout style

Slide 57

Slide 57

Slide 58

Slide 58

Slide 59

Slide 59

CSS JavaScript • CSS is declarative 
 (whole animation is known ahead of time) • CSS animations with transform & opacity won’t be impacted by the main thread • JS is imperative 
 (browser only really aware of the current frame) • Hardware acceleration isn’t automatic

Slide 60

Slide 60

SVG & Hardware Acceleration? • Not all browsers support it
• Good performance in general without it though

Slide 61

Slide 61

Slide 62

Slide 62

You have encountered an interface that requires animation. What would you like to use? (1) …?

Slide 63

Slide 63

Designing Interface Animation designinginterfaceanimation.com 20% O ! : “valhead”