By: Matthew Poulson
Want to use Animations
Know what to Animate
Know how to Animate
Help the user cope with state change.
Guide user's attention to what is important.
"Moving elements are a powerful tool to attract users’ attention. When designing an animation consider its goal, its frequency of occurrence, and its mechanics. "
-AURORA BEDFORD
(reduce the surprise of state change)
Guide the user to a new state.
As opposed to cut to state.
View more details
Bring attention to what is happening
Elements should respond to actions
60fps
render frames every 16ms
"...should be fast enough that it doesn't cause waiting, but slow enough that the transition can be understood."
Long: 300 - 400ms
Short: 150 - 200ms
Good
Bad
"Acceleration and deceleration changes should be smooth across the duration of an animation so that movement doesn't appear mechanical."
"Create a clear, smooth focal path in a single direction."
"When multiple elements remain visible during a transition, only the most important ones should be included. Some elements may disappear during the transition but reappear once the transition completes, if they are too distracting during the transition itself."
Good
Bad
"Associate newly created surfaces to the element or action that creates them. New surfaces usually emerge from radial or rectangular expansions from the point of touch."
Good
Bad
"Connect user input to screen reactions by using touch ripples to both indicate the point of touch, and to confirm that touch input was received. For touch or mouse, this occurs at the point of contact."
Most Properties that have units.
transform: translateX(1em);
transform: translateY(2em);
transform: scaleX(3);
transform: scaleY(4);
transform: rotateX(5deg);
transform: rotateY(6deg);
transform: rotateZ(7deg);
opacity: .8;
They are composite, and can be done by the GPU
Note: they trigger Paint
Note: they trigger Layout
Transitions
Keyframes/Animations
Animate a change of a property
Here we modify the `max-height` of an element
transition-property
transition-duration
Here we modify both the max-height and opacity of an element
transition-timing-function
transition-timing-function: ease;
transition-timing-function: ease-in;
transition-timing-function: ease-out;
transition-timing-function: ease-in-out;
transition-timing-function: linear;
transition-timing-function: steps(5, end);
transition-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
cubic-bezier(0.4, 0.0, 0.2, 1);
Now we add a transition-timing-function
Define the properties to apply at what point in the animation
Apply keyframes to an element
Define how those animations behave
animation-delay: <time>
animation-direction:
normal | reverse | alternate | alternate-reverse
animation-iteration-count:
infinite | <number>
animation-play-state:
running | paused
How do you Trigger them?
element:hover
element:focus
element:invalid
element:valid
element:enabled
element:disabled
element:indeterminate
element:in-range
element:optional
node.classList.add();
node.classList.remove();
node.classList.toggle();
Try to use CSS Selectors before you use JavaScript...
But you should be comfortable using JavaScript to manipulate the DOM
Sources