Skip to content

Commit d5c206c

Browse files
authored
Update animate-images-with-keyframes-using-css.mdx
1 parent bc18be5 commit d5c206c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

projects/animate-images-with-keyframes-using-css/animate-images-with-keyframes-using-css.mdx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,75 @@ Let's also take a look at this line of code:
107107
```
108108
animation: colorChange 2s infinite;
109109
```
110+
111+
- `colorChange` is the name of our animation
112+
- `2s` is the length in seconds of how long the animation lasts
113+
- `infinite` is indicating it will loop forever
114+
115+
The line of code above is attached to the `.box` class from our HTML file! Animations can only show up if they are defined in the `animation:`.
116+
117+
## Easing
118+
Easing in CSS animations is essential to understanding the pace in which an animation progresses over time.
119+
120+
<RoundedImage link="https://i.imgur.com/9C7DeEg.gif" description="easing demo from mdn web docs" />
121+
122+
Some common ones you'll see:
123+
124+
- `linear`: Constant speed
125+
- `ease`: Starts slow, speeds up, then slows down
126+
- `ease-in`: Starts slow, then accelerates
127+
- `ease-out`: Starts fast, then decelerates
128+
- `ease-in-out`: Combines `ease-in` and `ease-out`
129+
130+
These can differ and are added right in the `animation:` of your CSS.
131+
132+
```
133+
.tinker_bell {
134+
animation: bounce 1s linear infinite;
135+
}
136+
```
137+
138+
**Note:** Easing can get pretty complicated based on the type of motion you want to create! You can review the open source [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function) for more information on easing and animation examples.
139+
140+
141+
### Spin Animation
142+
143+
Think of the last time you saw a spinning loader:
144+
145+
<RoundedImage link="https://i.imgur.com/lW1fWrY.gif" description="spinning loader" />
146+
147+
This can be recreated with a spin animation like so:
148+
149+
```
150+
<div className="sensei">
151+
<img src="sensei.png" alt="club penguin gray sensei penguin" />
152+
</div>
153+
```
154+
155+
```
156+
/* spinning animation */
157+
@keyframes spin {
158+
from {
159+
transform: rotate(0deg);
160+
}
161+
to {
162+
transform: rotate(360deg);
163+
}
164+
}
165+
166+
.sensei {
167+
display: flex;
168+
justify-content: center;
169+
align-items: center;
170+
height: 100vh;
171+
animation: spin 1s linear infinite;
172+
}
173+
174+
```
175+
176+
Here, we're using the CSS function `rotate()` to establish which degree we want to start and end at. In this example, we're using the keywords `from` and `to` which are shortcuts for `0%` and `100%`.
177+
178+
The result of the club penguin sensei looks like this 🔥🔥
179+
180+
<RoundedImage link="https://i.imgur.com/YVnPHFA.gif" description="spinning club penguin sensei" />
181+

0 commit comments

Comments
 (0)