Practical Web Animation

A presentation at ffconf in November 2018 in Brighton, UK by Lisi Linhart

Slide 1

Slide 1

Practical Web Animation Lisi Linhart

Slide 2

Slide 2

Lecturing @ LISILINHART.INFO Twitter @LISI_LINHART Blog

Slide 3

Slide 3

Slide 4

Slide 4

Slide 5

Slide 5

Slide 6

Slide 6

Title Text the user

Slide 7

Slide 7

Title Text the user the browser

Slide 8

Slide 8

Animation for the Animation with the User Browser orientation attention feedback perceived performance perception

Slide 9

Slide 9

Animation for the Animation with the User Browser orientation web standards attention render engines feedback CSS vs. JS perceived performance performance perception devices

Slide 10

Slide 10

Animation with the Browser

Slide 11

Slide 11

4 things a browser can animate cheaply

Slide 12

Slide 12

4 things a browser can animate cheaply position translateX(-10px);

Slide 13

Slide 13

4 things a browser can animate cheaply position scale translateX(-10px); scale(0.5);

Slide 14

Slide 14

4 things a browser can animate cheaply position scale rotation translateX(-10px); scale(0.5); rotate(-25deg);

Slide 15

Slide 15

4 things a browser can animate cheaply position scale rotation opacity translateX(-10px); scale(0.5); rotate(-25deg); opacity: 0.5;

Slide 16

Slide 16

this is not performant

Slide 17

Slide 17

use the transform property 💪

Slide 18

Slide 18

order matters transform properties can be chained

Slide 19

Slide 19

codepen.io/danwilson/pen/eEYdgo

Slide 20

Slide 20

Rendering & Property Changes Javascript / Event

Slide 21

Slide 21

Rendering & Property Changes Javascript / Event Style Recalculations width, margin, left, .. Layout

Slide 22

Slide 22

Rendering & Property Changes Javascript / Event Style Recalculations Layout Paint background, box-shadow, outline, ..

Slide 23

Slide 23

Rendering & Property Changes Javascript / Event Style Recalculations Layout Paint Composite transform, opacity ..

Slide 24

Slide 24

Rendering & Property Changes Javascript / Event Style Recalculations Layout 1 frame Paint Composite

Slide 25

Slide 25

translateX(-10px); opacity: 0.5; try to limit yourself to CSS transform & opacity for most animations

Slide 26

Slide 26

promote elements to new layers if animated often & constantly

Slide 27

Slide 27

Creating new layers

Slide 28

Slide 28

Creating new layers 1. will-change property 2. 3D Transform 3. animated 2D transforms 4. being on top of a compositing layers 5. animated CSS filters

Slide 29

Slide 29

Slide 30

Slide 30

🤯 don’t create too many layers remove them if the animation is finished

Slide 31

Slide 31

Removing layers

Slide 32

Slide 32

DevTools

Slide 33

Slide 33

Slide 34

Slide 34

inspect & test your animations in your devtools

Slide 35

Slide 35

Javascript / Event Style Recalculations Layout Paint Composite

Slide 36

Slide 36

Animation for the User

Slide 37

Slide 37

ORIENTATION & TRANSITIONS

Slide 38

Slide 38

Title Text

Slide 39

Slide 39

ORIENTATION & TRANSITIONS 1 help with reorientation in the user 2 explain relationships between different information spaces

Slide 40

Slide 40

ORIENTATION & TRANSITIONS Example: VueJS Transitions

Slide 41

Slide 41

Title Text codepen.io/lisilinhart/full/rqRvxJ/

Slide 42

Slide 42

VueJS Transitions view is toggled when a button is clicked

Slide 43

Slide 43

VueJS Transitions component is transitioned in if view is the correct value

Slide 44

Slide 44

VueJS Transitions

Slide 45

Slide 45

VueJS Transitions

Slide 46

Slide 46

VueJS Transitions

Slide 47

Slide 47

VueJS Transitions

Slide 48

Slide 48

Title Text codepen.io/lisilinhart/full/rqRvxJ/

Slide 49

Slide 49

PERCEIVED PERFORMANCE

Slide 50

Slide 50

“Human perception of time is fluid, and can be manipulated in purposeful and productive ways.” Chris Harrison Faster Progress Bars: Manipulating Perceived Duration with Visual Augmentations

Slide 51

Slide 51

Chris Harrison, Zhiquan Yeo, Scott E. Hudson Faster Progress Bars: Manipulating Perceived Duration with Visual Augmentations animated progress bars reduced the perceived duration among the participants by 11%

Slide 52

Slide 52

PERCEIVED PERFORMANCE 0.1 seconds 1 second 5-10 seconds feels instantaneous user will feel the pause struggle to maintain the user’s attention Jakob Nielsen - Usability Engineering

Slide 53

Slide 53

Title Text tomswholesomefood.com.au

Slide 54

Slide 54

PERCEIVED PERFORMANCE The page is loading activity & progress indication Here is a skeleton screen of what content is being loaded Lazy loading & hinting While you’re waiting, here is some more information on how the process works using idle times to inform the user

Slide 55

Slide 55

PERCEIVED PERFORMANCE Example: Web Animations API

Slide 56

Slide 56

WEB ANIMATIONS API keyframes object or array: stages of the animation timings object: how it's animated (e.g. speed, delay, ..)

Slide 57

Slide 57

WAAPI KEYFRAMES keyframes object keyframes array

Slide 58

Slide 58

WAAPI TIMINGS OBJECT how fast should my animation run, how often should it run, what should happen after it’s finished?

Slide 59

Slide 59

CSS VS WAAPI CSS Animation

Slide 60

Slide 60

CSS VS WAAPI CSS Animation Waapi Animation

Slide 61

Slide 61

Title Text codepen.io/lisilinhart/pen/XxGqqx

Slide 62

Slide 62

WAAPI EXAMPLE animated cursor title element with the text clip-path for text in order to animate transform: scaleX(0)

Slide 63

Slide 63

WAAPI EXAMPLE clipping of text repeating the titles text with the CSS content property

Slide 64

Slide 64

WAAPI EXAMPLE getting the elements same duration for both animations

Slide 65

Slide 65

WAAPI EXAMPLE calling the animations

Slide 66

Slide 66

Title Text codepen.io/lisilinhart/pen/XxGqqx

Slide 67

Slide 67

WAAPI CONTROLS .animate() returns an animation object speeding up the animations when we click the title

Slide 68

Slide 68

Title Text codepen.io/lisilinhart/pen/rqgPNd

Slide 69

Slide 69

WAAPI CONTROLS

Slide 70

Slide 70

WAAPI CALLBACKS

Slide 71

Slide 71

WHY THE WEB ANIMATIONS API? • • • API provided by the browser • • choreographed & chained animations no extra Javascript code like for libraries can render animations over the compositor thread (no JS stalling) a native & more powerful alternative to CSS animations

Slide 72

Slide 72

Title Text codepen.io/vincentriemer/pen/vpLrWg

Slide 73

Slide 73

good news for safari 🎉 no edge yet 😔

Slide 74

Slide 74

good chances that it’s coming

Slide 75

Slide 75

polyfill for wider browser support https://github.com/web-animations/web-animations-js/tree/master

Slide 76

Slide 76

ATTENTION & FEEDBACK

Slide 77

Slide 77

FEEDBACK I recognised that you clicked this button giving a reaction to user input

Slide 78

Slide 78

FEEDBACK I recognised that you clicked this button giving a reaction to user input You entered some information, but it’s not correct cause & effect of the users input

Slide 79

Slide 79

FEEDBACK I recognised that you clicked this button giving a reaction to user input You entered some information, but it’s not correct cause & effect of the users input You submitted the form, but our system is still processing it making system activity visible

Slide 80

Slide 80

codepen.io/davidkpiano/full/WKvPBP/

Slide 81

Slide 81

ATTENTION

Slide 82

Slide 82

ATTENTION To get to the next step, click this prominent item showing possible actions

Slide 83

Slide 83

ATTENTION To get to the next step, click this prominent item showing possible actions We created this explanatory animation in order for you to better understand our process teaching the user about a process, storytelling

Slide 84

Slide 84

ATTENTION To get to the next step, click this prominent item showing possible actions We created this explanatory animation in order for you to better understand our process teaching the user about a process, storytelling You had to read a lot of information, so we added this kitten animation to entertain you adding fun and reinforcing branding

Slide 85

Slide 85

Title Text stripe.com/us/payments

Slide 86

Slide 86

ATTENTION & FEEDBACK Reactive Animation

Slide 87

Slide 87

JS + CSS VARIABLES

Slide 88

Slide 88

JS + CSS VARIABLES

Slide 89

Slide 89

JS + CSS VARIABLES CSS Variables are inherited from their parent, for better performance set them at the most specific level

Slide 90

Slide 90

Title Text 2018.ffconf.org

Slide 91

Slide 91

Title Text codepen.io/lisilinhart/pen/RqwZgg

Slide 92

Slide 92

JS + CSS VARIABLES a layer for each element that’s animated separately

Slide 93

Slide 93

JS + CSS VARIABLES values need to be between 1 and -1 for easier usage in CSS the css variables are set on the parent element, so all child elements have access to them

Slide 94

Slide 94

JS + CSS VARIABLES multiplying the variable between -1 and 1 with the value it should be moved around

Slide 95

Slide 95

Title Text codepen.io/lisilinhart/pen/RqwZgg

Slide 96

Slide 96

JS + CSS VARIABLES • easily debuggable • no excessive DOM manipulation • DOM node independent • great for reactive & physics animation • Transform: Individual Properties

Slide 97

Slide 97

Opportunities for Animation

Slide 98

Slide 98

make idle time more useful and interesting Opportunities for Animation

Slide 99

Slide 99

make idle time more useful and interesting guide the user in a process Opportunities for Animation

Slide 100

Slide 100

make idle time more useful and interesting guide the user in a process Opportunities for Animation explain relationships in the information space

Slide 101

Slide 101

make idle time more useful and interesting guide the user in a process Opportunities for Animation get the users attention explain relationships in the information space

Slide 102

Slide 102

Animation Resources

Slide 103

Slide 103

Animation Resources Animation At Work - A Book Apart Book by Rachel Nabors

Slide 104

Slide 104

Animation Resources Animation At Work - A Book Apart Twitch Channel by David Khourshid & Stephen Shaw keyframe.rs Book by Rachel Nabors

Slide 105

Slide 105

Animation Resources Animation At Work - A Book Apart Twitch Channel by David Khourshid & Stephen Shaw keyframe.rs Book by Rachel Nabors animationatwork.slack.com Slack Channel to get feedback & inspiration

Slide 106

Slide 106

Animation Resources Animation At Work - A Book Apart Twitch Channel by David Khourshid & Stephen Shaw basics to know about animation keyframe.rs Book by Rachel Nabors animationatwork.slack.com developers.google.com/web/ fundamentals/design-and-ux/animations/ Slack Channel to get feedback & inspiration

Slide 107

Slide 107

Animation Resources Animation At Work - A Book Apart Twitch Channel by David Khourshid & Stephen Shaw basics to know about animation keyframe.rs Book by Rachel Nabors animationatwork.slack.com developers.google.com/web/ fundamentals/design-and-ux/animations/ Slack Channel to get feedback & inspiration uianimationnewsletter.com inspiration for UI animation

Slide 108

Slide 108

“Users should only notice your animation if you need to attract their attention in that moment. Otherwise, micro-interactions and other transitions should be so seamless, users don’t even notice that there is animation” Heather Daggett - Animation At Work

Slide 109

Slide 109

Animate for the user, don’t create obstacles,