CSS Transitions & Animations
1
We use tech to connect human potential and opportunity with dignity & humility
Today’s objectives
2
Introduction to animations with CSS
3
Introduction to animations with CSS
4
2 common types for animations:
CSS Transitions
5
Transitions are typically applied when a user interacts with an element (e.g when a user hovers or clicks on an element)
To create a transition effect, you must specify:
div {
transition: background-color 0.5s ease;
background-color: red;
}
div:hover {
background-color: green;
}
CSS Transitions
6
CSS Animations
7
Animations can start directly on load of the page, but can also be triggered on interaction of the user.
CSS Animations can have more control than CSS Transitions in the steps until the end of the animation and can run indefinitely.
To create an animation effect, you must specify:
.element {
height: 200px;
/* animation-name must match @keyframes value */
animation-name: pulse;
animation-duration: 5s;
animation-iteration-count: infinite;
}
/* @keyframes <animation-name> with <percentage> steps */
@keyframes pulse {
0% {
background-color: hotpink;
}
50% {
background-color: yellow;
}
100% {
background-color: hotpink;
}
}
Note
8
Should not be overused, but can be powerful if used in correct places
CSS Animations
9
Work on final project
10