You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.2 KiB
2.2 KiB
CSS - Motion
Lesson Objectives
- Explain the roles in traditional animation and how they apply to computer animation
- Create basic transitions between a start and end state in CSS
- Write complex animations with multiple states
Explain the roles in traditional animation and how they apply to computer animation
- In traditional (hand-drawn) animation, there were two kinds of animators
- Keyframe artist
- Draws the main frames for the animation
- Inbetweener (tweener)
- Fills in the frames between each keyframe so it looks fluid
- Keyframe artist
- In computer animation, we act as the keyframe artist, and the computer is the tweener.
Create basic transitions between a start and end state in CSS
Define a start state and an end state
a {
background:yellow; /* start state */
}
a:hover {
background:green; /* end state */
}
Three main properties:
transition-property: background, left, top, height;transition-duration: 0.5s;transition-timing-function: ease;- ease
- linear
- ease-in
- ease-out
- ease-in-out
- cubic-bezier(n,n,n,n)
transition-delay: 1s;
Shorthand
transition: <property> <duration> <timing-function> <delay>
Write complex animations with multiple states
Transitions are great for going from one state to another, but sometimes you need more than a start and end state. To do this, there are two steps
-
Create a named animation with a set of keyframes.
@keyframes example { 0% {background-color:red; left:0px; top:0px;} 25% {background-color:yellow; left:200px; top:0px;} 50% {background-color:blue; left:200px; top:200px;} 75% {background-color:green; left:0px; top:200px;} 100% {background-color:red; left:0px; top:0px;} } -
Assign the animation to a rule and give it a duration
div { width: 100px; height: 100px; background-color: red; position: relative; animation-name: example; animation-duration: 4s; } -
Additional properties
- animation-timing-function
- animation-iteration-count (can be set to infinite)
- animation-direction
- reverse
- alternate
- animation-delay
- animation-play-state
- paused
- running