Welcome to part 3 of the series. This series is inspired by this awesome YouTube series by The Net Ninja.
We will start where we left in part 2, and continue with Mario Kart Animations.
We will leave Mario with his infinite animation and bring his brother Luigi, to learn further animation. So, go ahead and add Luigi in index.html
Luigi
Next, also add styles for him in style.css
Luigi styles
It will show Luigi in browser.
Luigi in browser
We will use the same animation for Luigi as Mario, but we will give his direction as reverse.
reverse
The animation-direction: reverse property, will have Luigi go from right to left.
Luigi reverse
Now, you might have noticed from Mario that he is slowing down towards the right end.
This is because of animation-timing-function, which is like the transition-timing-function we learnt in part 1
It is by default ease, which slow start, then fast, then end slowly.
We will make Mario travel with linear speed i.e. with the same speed from start to end.
linear speed
So, Mario travel at linear speed now.
linear mario
All the different animation properties which we have used for Mario and Luigi, can be used in a single line with shorthand notation.
We will learn it with clouds. So, let’s add two clouds images in our sky.
Clouds
It will show these two clouds.
Two clouds
Let’s give the two clouds some positioning, so that they overlap each other.
cloud positioning
It will show them as below.
Cloud positioned
Now, we will animate them with the shortcuts. The animation shortcut takes animation name, duration, timing-function, iteration-count, direction in order.
animation shortcuts
It will show these clouds moving slowly from right to left.
Cloud moving
We will now learn about chaining two animations. We will create a jump animation for Mario. Now, it will have 3 states. So, we cannot use from and to. We will use percentages in such cases.
3 state animations
Now, we will chain it. As you can see, we are using shorthand notation for Mario’s earlier drive animation. After that we are using a comma(,) and putting the jump animation.
Chaining animation
Now, our Mario will jump once for 0.3s after a delay of 1.2s, with ease timing.
Jumping Mario
It completes our Mario animation and part 3. You can find the code for the same here.