Html5 Book

HTML5, the latest version of HTML, the formatting language that produces web pages - including the one you read this on, of course - has taken the web development community by storm.

On one hand, it is easy to learn; On the other hand, it has the potential to evolve and then pose a serious threat to Flash, which is more or less synonymous with impressive animations.

HTML5 has come about thanks to the cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG), in their collective pursuit to make the web a true treasure trove for mankind.

In this animation, you will:

  • Move a balloon and its reflection across a background of floating hot air balloons.
  • Make the movement smooth by using the timer functions.
  • Make them move forward and backward seamlessly.

Finding a good book to master HTML5 can be very challenging: there are so many around - most with eye-catching titles and very complex substance.
Therefore, Vivax Solutions strongly recommends Core HTML5 Canvas for those who really want to delve into HTML5.
Please click the image to access Amazon:

Creating 2-D Animations on Canvas

The flight of hot air balloon

In this example, the background is an image made by using CSS in canvas element.

The balloon and its reflection are produced by two images.

The images are moved across the background by using JavaScript.

<script type="text/javascript">
var canvas = document.getElementById('Canvas_T');
var context = canvas.getContext('2d');
// image of the top balloon
var imgObj1 = new Image();
// image of the second balloon
var imgObj2 = new Image();
var i = 0; var j = 1; var x; var y;
// function for the movement
function circ() {
i = i + j;
if (i == 400) { j = -1; }
if (i == 0) { j = 1; }
context.clearRect(0, 0, 500, 400);
x = i;
y = Math.round(100 + 15 * Math.sin(i * Math.PI / 180));
context.drawImage(imgObj1, x, y);
imgObj1.src = '../images/hot.png';
context.drawImage(imgObj2, x, y + 180);
imgObj2.src = '../images/hot1.png';

<-Go to Thirteenth Lesson Go to Fifteenth Lesson->