HTML Academy
Moving objects vertically
2D Transforms3/32
Back to the list of tasks
  • 1. Moving objects horizontally
  • 2. Moving objects vertically
  • 3. Fireball training
  • 4. Increasing and decreasing the size
  • 5. Defending the city
  • 6. The beginning of the journey
  • 7. The maze
  • 8. The battle, part 1
  • 9. The battle, part 2
  • 10. Test: The mysterious card
  • 11. The battle, part 3
  • 12. Test: The shattered crystal
  • 13. The final battle
  • 14. Features of transform-origin, part 1
  • 15. Features of transform-origin, part 2
  • 16. Features of transform-origin, part 3
  • 17. Features of transform-origin, part 4
  • 18. Centering with transform: translate
  • 19. Rotating the text in blocks
  • 20. Rotating the text in the background
  • 21. Custom shadows
  • 22. On-hover effects: buttons, part 1
  • 23. On-hover effects: buttons, part 2
  • 24. On-hover effects: buttons, part 3
  • 25. On-hover effects: the gallery
  • 26. The “stack” of cards
  • 27. Preparing the round menu
  • 28. Round menu, step 1
  • 29. Round menu, step 2
  • 30. Round menu, step 3
  • 31. The round menu, final part
  • 32. Test: Arranging the cards
Increasing and decreasing the size
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Fireball training

Finding himself in a dangerous fantasy world with trolls and werewolfs waiting around every corner, Pendalf must be able to fend for himself. And the best means of attack and defense for any self-respecting battle magician is, as you know, fireballs.

Let’s learn how to throw fireballs at targets in order to protect Pendalf from enemies as the need arises.

To do this, we will utilize the movement spells that we previously learned: translateX, translateY, as well as a new, more laconic spell that combines movement along two axes at once into one function (translate):

transform: translate(movement along the X-axis [, movement along the Y-axis])

The square brackets indicate that the Y-axis offset value is optional. You don’t need to write square brackets in the code, since the two values are simply listed separated by commas, and they can have different units of measurement. If you do not specify a Y-axis offset value, but write translate (X-axis offset), then the offset value along the Y-axis will be considered equal to 0, and the function will work similar to translateX.

// These functions all produce the same result:
transform: translate(100px);
transform: translate(100px, 0);
transform: translateX(100px);

Let’s finally get down to making fireballs!

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Fireball training</title> <meta charset="utf-8"> <link rel="stylesheet" href="world.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="world"> <div class="wizard"> <div class="fireball fireball-1"></div> <div class="fireball fireball-2"></div> <div class="fireball fireball-3"></div> </div> <div class="target target-right"></div> <div class="target target-top-right"></div> <div class="target target-top"></div> </div> </body> </html>
CSS
.fireball-1 { } .fireball-2 { } .fireball-3 { } .wizard { top: 244px; left: 30px; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. Use the translateX function to move .fireball-1 forward by 310px so that it hits the bottom right target.
    2. Move .fireball-2 vertically up 190px so that it hits the upper target.
    3. At the same time throw the last ball, .fireball-3, forward 290px and up 190px so that it hits the upper right target.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.