Chapter 7 : CSS Animations Flashcards
What do we need to specify to use CSS3 animation?
- Specify some keyframes for the animation
What will happen when we specify CSS styles inside the @keyframes rule?
- The animation will gradually change from the current style to the new style at certain times
- To get an animation to work, we must bind the animation to an element
Create a changeColor keyframes and assign it to a <div> element
div
{
width: 500px;
height: 500px;
border-radius: 50%;
background-color: red;
animation-name: changeColor;
animation-duration: 4s;
}
@keyframes changeColor
{
from {background-color: red;}
to {background-color: purple; }
}
- CSS will automatically assign color when background color is changed ( Red -> Purple -> Blue )
Create a changeColor keyframes and assign it to a <div> element, but it requires
1. Red , then
2. Yellow, then
3. Blue, then
4. Green
div
{
width: 500px;
height: 500px;
border-radius: 50%;
background-color: red;
animation-name: changeColor;
animation-duration: 4s infinite;
}
@keyframes changeColor
{
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
Create a changeColor keyframes and assign it to a <div> element, but it requires
1. Red , then
2. Yellow, then
3. Blue, then
4. Green
Also change the div element position
div {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: red;
position: relative;
animation-name: changeColor;
animation-duration: 4s;
}
@keyframes changeColor {
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;}
}
What does animation-dealy does?
- Specifies a dealy for the start of an animation
Create a div element to specify delay for 2 seonds before animation starts playing
div
{
width: 100px;
height: 100px;
position: relative;
background-color:red;
animation-name: changeColor;
animation-duration: 4s;
animation-delay: 2s;
}
What property should we use to specify the number of times an animation should run?
- animation-iteration-count
What are the 2 values for animation-iteration-count property?
- Number ( 1, 2 )
- Loops though the numbers define
- infinite
- animation-iteration-count: 3 ; / animation-iteration-count: infinite ;
What is the usage of animation-direction property?
- Used to let an animation run in reverse direction or alternat cycles
What are the 2 values for animation-direction property?
- reverse
- alternate
- animation-direction: reverse
animation-direction: alternate
What does the animation-timing-function property specifies?
- The speed curve of the animation
List out all the 6 values for animation-timing-function property
- ease
- linear
- ease-in
- ease-out
- ease-in-out
- cubic-bezier(n,n,n,n)
What is the shorthand property for
div {
animation-name: changeColor;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
div
{
animation: changeColor 5s linear 2s infinite alternate
}