Introduction to Animation on the Web
20 May 2024
Updated: 20 May 2024
ZOOOOOOM! 🔍
Is everything big enough and are we in dark mode?
Housekeeping 🧹
- Everyone is encouraged to have their cameras on
- Session will be recorded and made available by the learning team in a few weeks
- Content will also be available on my website after the session
- We will stop for questions along the way and should have some time at the end
- Animations may be a bit laggy due to MS Teams
🎞️ Animation on the Web 🌐
Nabeel Valley
- From Pretoria
- Currently in NL
- Full Stack Developer
- @ Entelect since July 2023
- On the Digital Platform team at Rabobank
- Like making things
- nabeelvalley.co.za
- @not_nabeel
- @nabeelvalley
Things ✌️ Talk About
(the agenda)
- Why do we need animations?
- Animating in CSS
- Principles of Animation
- When to ignore all of this
Why do we need animations? 🤷
- User Feedback
- Draw attention to something
- Highlight personality
- Juicyness
☝️ A Quick Note on Custom Properties
These examples make extensive use of CSS Custom Properties so it’s good to have a basic understanding of them
Animating in CSS 🧑💻
- Transitions
- Keyframes
- View Transitions
- Optimizing Animations
Transitions 🎢
- Related to state changes
- Control change of properties over time
- Implicit transitions
- Intermediate states defined by browser
Setting up a Transition 🔧
We need something to animate
Using Transitions 👷
Questions?
📏 Shorthand Syntax
Multi Property Transitions ♾️
🤏 Multi Property Transition Shorthand
Combining Transitions 🤝
Timing ⏱️ Functions
⏪ Recap Transitions
- Syntax for Transitions
- Defining transitions based on DOM state
- Transitioning multiple properties
- Shorthand syntax
- Combining transitions
- Timing functions
Animations 🎞️
- Run as soon as the element or class is added
- More complex animations possible
- Can be independent of state
- Implicit or Explicit
- We can define intermediate states
Using Animations 📹
Questions?
State Based Animations 🔛
Multi Property Animations 🍿
⏪ Recap - Animations
- Syntax for Animations
- Syntax for Keyframes
- Defining animations based on DOM state
- Animating multiple properties
View 🕶️ Transitions
- Triggered by JS
- Transitions content as well as properties
- Can be used across navigations (browser support in progress)
Triggering a Transition ✅
Questions?
The Default Transition 😐
- 2 Different transitions
- Fades old content out
- Fades new content in
CONTENT
Understanding the Transition 🤔
Questions?
CONTENT
⏪ Recap - View Transitions
- Trigering a View Transition
- The Default Transition
- Customizing a Transitions
Animation Optimization ⚡
- Size changes are costly
- Some properties are GPU accelearated
transform
filter
opacity
- Using
will-change
- Last resort
- Do not apply to too many elements
Premature optimization? It’s relatively easy to write it correctly first time
🔮 Will-Change
- Used to inform the browser that certain elements of a property will be changed
- The browser can use this to optimize the transition/animation of the property
The 12 Principles of Animation 📔
- Introduced in “The Illusion of Life” by Frank Thomas and Ollie Johnston
What do we do with our new found skills?
1. Squash and Stretch 🪢
Illusion of weight and volume
2. Anticipation ⌛
Using small actions to indicate an action is about to happen
3. Follow Through and Overlap 🐾
Adding movement after an action
4. Arcs ⭕
Nature moves in arcs
5. Slow In & Slow Out 🦥
Easing in and out of an action
6. Timing ⌚
Number of frames for a given action
7. Secondary Action 🔂
Additional actions that enhance an action
8. Exaggeration 💥
Provide dramatic effect
9. Staging 🎭
Direct the audience attention
10. Straight Ahead & Pose to Pose 📼
Two different techniques for determining frames
- Straight ahead - Draw frames consecutively
- Post to Pose - Draw frames at start and end the figure out what’s in between
11. Solid Drawings 🖼️
Make it feel like 2D shapes occupy a 3D space
12. Appeal 🌟
- Simple
- Clear
- Compelling
Make the viewer feel something
⏪ Recap - Principles of Animation
- Squash and Stretch
- Anticipation
- Follow Through and Overlap
- Arcs
- Slow In & Slow Out
- Timing
- Secondary Action
- Exaggeration
- Staging
- Straight Ahead & Pose to Pose
- Solid Drawings
- Appeal
🪟 Frameworks and Libraries 📚
- TailwindCSS Animation Properties - Primitives for building animations
- Animate.css - Predefined animations and transitions
- Frame Motion - More sophisticated Javascript driven animations
For defining animations, not design systems
When not to use Animations 🚫
- If the the user has enabled
reduced-motion
- If it will add too much visual noise
- If they will distract the user
- Responsiveness and accessibility concerns
Suggestions 💡
- Use animations lightly
- Less is more, small interactions go a long way
- Define your identity and use animations to enhance that
- Understanding interactivity on different screen types
- Animations should have a purpose
Case Study 🕵️
- Changing themes
- Navigation dropdown
- Background svg
- Link hover
- Twitter link
- Sense of identity
- Maximalism can work too
References and Further Reading 📖
MDN
Principles of Animation
- The Illusion of Life - The 12 Principles
- 12 Principles of Animation
- 5 Ways to Boost Your Game Juice
- Apply the 12 Principles of Animation to Web Development