Monday, 21 March 2011

Accessibility

Introduction


A couple of weeks ago, I had a chat with a colleague and friend of mine; who is also a User Experience Analyst, regarding the Do’s and Don’ts when designing a user interface (UI). He explained that before starting the design stage of a web page or a software application, one should investigate what type of audience and users will be using this application. He explained that one of the most difficult tasks he ever had, was to design a UI for a product that was localized in 14 different languages. Reasons being, that when you are designing such UI, one should take in consideration Cultural and National differences especially when choosing UI colours and icons. One should be aware that a colour in one country may mean peace of mind and success, while in a different country it means danger and failure. On the other hand choosing an icon is a bit trickier. Let’s assume that we need an icon that represent a user account, is the following icon valid?
Some will say YES, but I think women will complain because the icon represents a male. Same applies for different races having different skin colour. So Icons should be generic as much as possible.
I thought that catering for different cultures and races are the only concerns when designing a suitable UI. I was wrong. This week, our lecturer invited a professional web designer consultant that during the presentation she explained that we should also consider Accessibility.
Accessibility is defined as the ‘ability to access’, and in web development this means that a web site has to be fully accessible by users with physical disabilities.

In this blog I will explain what I’ve learned during the presentation.

Sensory impairments


After the presentation, I did some research on what type of disabilities exist that may prevent users from accessing a web site. Several sources mention Sensory impairments, disabilities related to the human five senses; sight, hearing, smell, touch and taste. Obviously when dealing with web accessibility the main concerns are sight, hearing and touch.
Not everyone is aware that unfortunately these conditions can be combined; a person can have more than one disability. In fact, complex conditions like deaf and blindness exist (dual sensory impairment) and is not rare amongst conditions.
Some disabilities are Congenital (from birth) or Acquired (developed as time goes by). For example, some people may lose sight as they get older, others are born blind.

Frustration


Part of the presentation we did in class, the presenter showed us a couple of videos where persons having difficulties and disabilities shared their experience. Mainly I noticed that these persons are more interested in the contents of a web site rather than the aesthetical appearance. Some background colours and animations we add to make an eye catchy web site sometimes make accessibility difficult or impossible for disabled persons. Not being able to read the latest news or to play a game makes a person emotionally frustrated.

I must help


What should web developers do to make a web site fully accessible?
To describe this, I created a list that I collected from various sources:
  • A web page should enable the user to increase fonts and zoom without altering the web page contents.
  • Use online resources to check how a colour blind person will see your web site. (http://www.vischeck.com/vischeck/vischeckURL.php)
  • Use heading tags to enable users to using key strokes to navigate between titles.
  • When using images, use the <img>, alt attribute and provide a short description. Screen readers will read the description and will skip the image.
  • Extra care should be taken when using animation (Example: Flash and JavaScript). Flashing colours may disturb the user.
  • Try to make your web site accessible only by keyboard. Some users are not able to use the mouse.

Some examples


Colour vision

Using an online simulation http://www.vischeck.com/vischeck/vischeckImage.php I processed an image and the following images shows the result obtained. Some of the flags are completely different:

Text resize

A well designed web page will not change the layout when increasing and reducing the font size. The following two examples show how the BBC news web page maintains the layout while changing font size.

Alternative text

When using screen readers, images are skipped. So a visually impaired person using a screen reader will not be aware that the web page contains images. When using the <img> tag to include an image, web developers should provide a short description in the alt attribute. Screen readers are able to detect and interpret the text within the alt attribute. The following example shows the images within the BBC news ‘Features and Analysis’ section. Each image within this section contains a suitable alternative text.

Some resources


I found the following resources very interesting:

Conclusion


Web sites have no geographical boundaries and can be accessed by users from different cultures and locations, 24 hours a day, 7 days a week. To ensure that a web site content is well interpreted by different users, organizations provide a localized version of their web site.
Sometimes when we design a web site we assume that everyone can see our animation, listen to a background music or able to click a button.  We forget that lot of users have difficulties doing basic tasks like clicking and using the mouse.
When web sites are not accessible, users are frustrated. Lot of tools exist to test your web site for accessibility.
Having a disability is not easy. Let’s not make it more difficult...


Sunday, 13 March 2011

Extensible Markup Language - XML

Introduction

If you’re experiencing web developing, one thing you should know is that an HTML page is made up of three components:
  • The HTML markup
  • The CSS
  • The data
Web experts suggest that when designing a web project, the HTML and the CSS should be contained in two separate files. Having the HTML markup and the formatting styles in two separate files, enables you to easily maintain your code and re-use the code in other projects.
But what about the data?
Extracting the data from an HTML file into a separate file is the main aim of XML (Extensible Markup Language). The main advantage of having the data in a separate file is that users having no experience in HTML markup can easily update the data. XML is easy to use and easy to understand, in-fact lot of parsers exists that can interact with XML files. Web developers can create their own tags; making the code more intuitive. But the main advantage is that XML is platform independent and can be interpreted by many programming languages (example Java and NET) and software applications.
In this blog I will describe my experience and what I’ve learned while performing a task assigned by my tutor.

 

XML

Components

Declaration

Every XML file should start with a declaration that describes the XML version and encoding used. A typical XML declaration is as follows:
<?xml version="1.0" encoding="UTF-8"?>
W3C states that the XML declaration is not only good practice but also mandatory. A good article can be found at http://www.ibm.com/developerworks/xml/library/x-tipdecl.html

Root

All elements within an XML file MUST be contained within a root element, only one root element can exist within an XML file. The following example shows a simple XML file with a root element called student.
<?xml version="1.0" encoding="UTF-8"?>
<student>
<idnumber>12345</idnumber>
<name>omar</name>
<surname>zammit</surname>
</student>

Elements

In an XML file, values MUST be declared within tags. Tag names are case sensitive and when opening and closing tags one must ensure that the proper name is assigned. For example the following syntax is INVALID:
<NAME>omar</name>
Each element must have a closing tag and must be nested correctly. The following syntax is INVALID because the closing tags are not properly nested:
<student>
<idnumber>12345</idnumber>
<name>omar
<surname>zammit
</name>
</surname>
</student>
Similar to programming languages, I recommend to use indentation. This will not only assist you while developing the XML file but will help others understand your code.

Attributes

Data related to an element can be stored in an XML attribute. Attributes MUST be declared within quotes and in an opening tag as follows:
<student name=”omar” surname=”zammit”>
</student>

Comments

Similar to HTML markup, commenting in XML can be achieved by adding the following syntax:
<!- - Comment goes here - ->

 

DTD

DTD uses

Document Type Definition or DTD is used to define how an XML should be structured. The DTD can be used by applications to validate an XML file and to ensure that the XML file is well formed. The DTD ensures consistency between multiple applications when accessing the same XML file.

Embedded or external

The DTD can be part of the XML file (embedded) or in a separate file (external). The following syntax is used to embed the DTD into an XML file.
<!DOCTYPE student[
                DTD Code goes here…
]>
An external DTD can be linked to an XML file by using the following code:
<!DOCTYPE student SYSTEM “student.dtd”>
The SYSTEM syntax indicates that the file is not embedded. This should be followed by the DTD file name “student.dtd”.
In both cases mentioned above, student is the XML root tag.

Declaring elements

Elements are declared using the ELEMENT syntax. For example, to declare a parent element that has multiple child nodes, the syntax is as follows:
<!ELEMENT student (studentid, name ,surname)>
Where, student is the parent node and studentid, name and surname are the child nodes. Following the declaration above, each child node should be declared individually as follows:
<!ELEMENT studentid (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
Where #PCDATA indicates the type of data that is stored. For more information on what types are supported, refer to http://www.w3schools.com/dtd/dtd_building.asp.
When designing the DTD, one should also add the element occurrence; if multiple elements having the same name can exist within a parent node. Let us assume that we have the following declaration:
<!ELEMENT student (studentid, name ,surname, project)>
This indicates that a student parent node can have the following child nodes:
  • Only one studentid
  • Only one name
  • Only one surname
  • Only one project
But we all know that life as a student is not that easy, and in-fact a student will have multiple projects. To instruct the XML file that multiple projects can exist, the ‘*’ notation is used. So to allow multiple projects the DTD must be changed as follows:
<!ELEMENT student (studentid, name ,surname, project*)>
The following notation is used to define occurrences:

Notation
Occurrence
Example
No notation
Only one
<!ELEMENT student(name)>
+
One or more
<!ELEMENT student(address+)>
*
Zero or more
<!ELEMENT student(project*)>
?
Zero or one
<!ELEMENT student(spousename?)>
|
Either or
<!ELEMENT student(parttime | fulltime)>

Declaring attributes

Attributes in DTD are declared using the ATTLIST syntax. For example, the following code declares a student having name and surname as attributes:
<!ATTLIST student name CDATA>
<!ATTLIST student surname CDATA>
Where CDATA indicates the attribute data type (in this case the data is Characters). Other properties can be added to an attribute, for example the following code defines that the student name cannot be empty and is required:
<!ATTLIST student name CDATA #REQUIRED>
The following code defines the default value (example Malta) for an attribute:
<!ATTLIST student nationality CDATA Malta>
For a full list of data types and other properties, refer to http://msdn.microsoft.com/en-us/library/ms256140.aspx

 

XSL

The Extensible Style sheet Language (XSL) and XSL Transformation (XSLT) enable web developers to apply formatting to XML files. To apply a style sheet to an XML file is similar to applying a style sheet to an HTML; an XSL file must be linked to an XML file. To describe XSL, let us assume that we have the following XML file having a list of students:
<?xml version="1.0" encoding="UTF-8"?>
<students>
                <student>
                                <studentid>001</studentid>
                                <name>Omar</name>
                                <surname>Zammit</surname>
                                <coarsecode>bsc01</coarsecode>
                </student>
               
<student>
                                <studentid>002</studentid>
                                <name>Gregory</name>
                                <surname>Mifsud</surname>
                                <coarsecode>bsc01</coarsecode>
                </student>

                <!--More students…….-->

</students>
If we want to format this XML file and display the student details in an HTML <table> tag, the XSL file should be as follows:
Similar to an XML file, the XSL should start by declaring the version and the encoding used (Line1).
In lines 2 to 3 the style sheet version is declared followed by the official W3C namespace (http://www.w3.org/1999/XSL/Transform).
The match=”/” syntax at line 4 is an XPath expression and means that the template applies to the whole document.
NOTE: XPath is a language that enables you to navigate in an XML document, for more information refer to http://www.w3schools.com/xpath/default.asp
Line 6 to 15 contains plain HTML markup and defines a title using the <h1> and a <table> with table headers.
The <xsl: for-each select = "students/student"> at line 16 is used to loop within elements in an XML file. In this example an iteration is done for each student element within students root tag.
The actions for each iteration are declared between lines 17 and 22. Using the <xsl:value-of select="element name"/> the element child nodes are displayed into a table cell. The iteration is closed at line 23.
From lines 24 onwards the closing tags are declared.
At this stage the last thing to do, is link the XML file with the XSL. To achieve this the following line should be added in the XML file just below the XML declaration:
<?xml-stylesheet type="text/xsl" href="studentstyle.xsl"?>
Where type is the template formation and href is the style sheet path. The following screenshots shows the formatted file when opened using an Internet browser.

XPath

As described above XPath provides several functions that enables you to navigate through and extract information from an XML file. Besides the for-each select and value-of select functions described above, XPath provides also conditional functions. For example, to display only BSC01 students from the XML file described above the code should be modified as follows:
At line 17 the if statement is added to check the coarsecode element value. If the value is bsc01 a new row with the student values is added. At line 24, the if statement is closed.
For more information on XPath, refer to http://www.w3schools.com/xpath/default.asp.
  

Task Description

This blog describes my experience while performing a task assigned by my tutor. The task consists of the following stages:
  • Create an XML file to keep the following data about a student project:
    • student name
    • student ID
    • project title
    • project category
    • abstract
    • date submitted.
Try to use both elements and attributes to describe the data.
  • Validate the XML
  • Create a DTD Schema for the XML file
  • Use validation tools to validate the XML against the DTD schema

 

The task

Design the XML

Similar to a programming project, it is recommended that before building the XML file a design of how the XML file is going to be structured is created.
Various notations exist to design the structure of an XML file, some prefer using UML (http://www.xml.com/pub/a/2002/08/07/wxs_uml.html). Personally I prefer the following sequence:
1.    List down all the information
2.    Identify elements and attributes
3.    Group the information into a hierarchy tree.     
4.    Identify the occurrence of each element; how many elements can exists.
5.    Create the XML file.
6.    Create the DTD.
7.    Validate both XML and DTD.
The following image shows the tree structure after completing the sequence above:
The following legend, enables you to understand well the notation used in my design. Note that in my design I also included element occurrences using the ‘*’ symbol. Unless the occurrence is specified only one child element can exist within a parent node.

Developing the XML file

Using the design mentioned in the previous section, I created the XML file using an XML editor. In this section each part of the XML file is described.
Line 1 contains information on the XML version and the encoding used. The encoding used in this task is the default encoding for XML files,  UTF-8 (Unicode Transformation Format 8).
All XML elements should be located between an XML Root element. The XML Root <projects>, is opened at line 2 and closed at line 15 </projects>. Within the <projects> root element, multiple students can exist but for clarity I added only one student in the example code above.
Elements related to a student are added within a <studentproject> element, declared at line 3 and closed at line 14. This element contain the <studentid>, <name>, <surname> and multiple <project> elements. Note that a student may have more than one project.
The <project> element has two attributes, these describe the project title and the project category. In addition the <project> element contains the <abstract> and <datesubmitted> elements.
The XML syntax, was validated using the w3cschool XML validation tool at http://www.w3schools.com/dom/dom_validate.asp.

Adding the DTD schema

The Document Type Definition (DTD) for the XML schema is embedded within the XML file as follows:
The XML root element projects, is declared within the DOCTYPE tag at line 2.
At line 3 the studentproject element is declared as a child node within projects. The ‘*’ notation indicates that within the projects element, multiple studentproject can exist.
In line 4, the child nodes within the studentproject are declared. The ‘*’ notation indicates that multiple project elements can exist within a studentproject. Since no notation has been assigned to studentid, name and surname, only one element of these can exist within a studentproject.
In lines 5 to 7, each child node within studentproject is declared as #PCDATA.
The project child node declared at line 8 contains 2 child nodes (abstract and datesubmitted) and two attributes (projecbtitle and projectcatebgory). The attributes are declared in lines 11 to 14. 
The XML syntax, was validated using the w3cschool XML validation tool at http://www.w3schools.com/dom/dom_validate.asp.

Validate result

Besides the validation tools provided by W3C schools I used some other validation tools. Amongst others I used http://validator.w3.org/#validate_by_input, this web site enables you to upload XML files, direct input the code or locate an XML file by entering the URL. The following report was generated when validating my XML and DTD file:
To ensure that the validation tool is working correctly, I removed a couple of elements and checked the file again.
When using this validation tool, the error messages are very intuitive and descriptive. The following is an error example:

 

Good to have

Sometimes XML structures can get very complex, and using simple text editors is time consuming. For business use, I recommend using an XML Integrated Development Environment like Altova XMLSpy (http://www.altova.com/xml-editor/)  or Adobe Dreamweaver (http://www.adobe.com/products/dreamweaver/).
If you’re a student and want to experience and learn XML, lots of free XML editors exist that can be downloaded from the web. Most important is to use a reliable validation tool before submitting an XML file.

 

Conclusion

XML is widely used to transfer data between applications, most common programming languages like Java and NET provides classes that interact with and process information from XML files. XML is not difficult to learn and very easy to use. XSL and XSLT enables web developers to apply formatting to an XML file. When creating an XML file ensure that the structure is conform with the W3C recommendation.

Friday, 4 March 2011

JavaScript - The Next Step

Introduction

When dealing with business organisations, an eye catching web site it’s a must. Mainly, organisations use their web site to promote their products and to reach customers. A web site has no geographical limits and provides a competitive advantage. The infrastructure (Internet) enables organisations to reach customers all over the world.
To enhance a web page and make it more attractive, web developers can use JavaScript to create animations and interactive objects. Such web pages are known as DHTML or Dynamic HTML pages.

Why Dynamic? 
Pages are Dynamic because the contents can change according to user actions. For example, contents can change when a user clicks a button or move the mouse over an object.  
This blog describes my experience while creating and implementing a JavaScript animation project assigned by my tutor.

My First Interactive Project

Web pages can be designed to update the contents when a user performs an action. This can be achieved using Event Handlers.  To describe Event Handlers, I created an interactive web page that performs some actions and uses the onmousemove and onclick event handlers.
The aim is divided in two:
  • Create a picture that moves when the user hovers the mouse.
  • While hovering, if the user clicks the mouse, a copy of the picture is inserted where the user clicked. 
The HTML markup page consists of the following code:
 
The <div> tag in line 40 contains all Event Handlers. The JavaScript function onMove() is called when the user hovers the mouse over the <div> tag. The JavaScript function onClick() is called when the user clicks in the <div> tag area.
The <div> tag between lines 42 and 45 displays the current mouse position using <span> tags. The mouse positions (X and Y) are updated automatically when the mouse moves.
The <img> tag at line 47 moves with the mouse pointer (cursor).  Note that the position style is set to absolute, this instructs the HTML that the image is not fixed; this enables the JavaScript function to move the image.
The JavaScript function onMove() is executed when the user hovers the mouse over the <div> tag described above.
When an event occurs a JavaScript event object is created. This contains additional information related to the event that has occurred. For more information refer to http://www.elated.com/articles/events-and-event-handlers/.
Amongst others the event object has the mouse X and Y positions. Where;
  • X – is the cursor relative distance in pixels from the left.
  • Y – is the cursor relative distance in pixels from the top.
In lines 9 and 10, the X and Y  cursor coordinates are stored in variables ex and ey respectively.
In lines 12 and 13, using the getElementById(), the image top and left positions are changed to variables ey and ex.
In lines 15 and 16, the <span> tags are updated with the new values using the innerHTML.
The JavaScript function onClick() is called when the user clicks on the <div> tag (described previously). Similar to the onMove() function, the X and Y cursor coordinates are stored in variables ex and ey. These coordinates reflects the new image position.
In line 24 the <div> tag is stored in a variable called mainDiv. Using the createElement() method a new image is created and stored in a variable called imageNode. The new image properties are defined in lines 27 to 31. Using the appendChild(), the new image is added to the <div> tag in line 33. The final output is shown in the screenshot and video below:

Animation

The setTimeout() method

The setTimeout() method is used in JavaScript to call functions after a specific time interval. The following button when clicked, waits 5 seconds and then calls the displayHello() function.
The time specified in the setTimeout() is in milliseconds and the function is only executed once. 

The setInterval() method

The setInterval() method is used in JavaScript to call a function continuously after a specific time interval. The function will keep executing similar to an infinite loop until clearInterval() is called. The following example shows a simple timer program.
Within the HTML <body> tag the following objects are added:
  • In line 18, a <span>tag is used to display the time
  • In line 19, an <input> object is used to call the increment() function every second. This function is declared in lines 10 to 13.
  • In line 20, an <input> object is used to call the clearInterval() method and stop the timer.
Note,to use clearInterval(), the setInterval() method must be assigned to a variable (timerObject).

Task Description

This blog describes my experience while performing a task assigned by my tutor. The task consists of the following stages:
  • Using HTML, CSS and JavaScript and some images, create a web page and an animation of a man running.
  • Add functionality to enable the user to speed up and slow down the animation.
  • Add a function that enables the user to ‘throw’ an obstacle and stop the runner.
  • Add a custom feature.

My Design

The project

The project files are divided in three:
  • The HTML code – this file contains all HTML markup tags
  • The Style sheet – this file contains all CSS styles
  • The Scripting file – this file contains all JavaScript functions and variables
The HTML file is linked with both the style sheet and the scripting file as shown in the following code:

The HTML code

The HTML markup for my task is made up of the following <div> tags:

The SeparatorDivTop and SeparatorDivBottom

These two <div> tags are used to display two different images around the animation (top and bottom). All attributes are declared within an external style sheet. The two CSS blocks that define the properties are shown below:

The MainDiv

This <div> tag is used to contain all the animation and is made up of the following four <img> tags:
  • fence – the background image
  • man – the running man
  • car  an image for my custom animation
  • ball – the image that is used as the obstacle.
The HTML markup is as follows:
Note, since car and ball are only visible when the user performs an action, by default these images should be hidden. To hide an image in CSS, you must assign the none value to the display property.

The ControlDiv

This <div> tag is used to contain all user controls. Within this <div> tag a user can perform the following actions:
  • Start or Stop the running man
  • Increase or reduce speed
  • Launch the car animation
  • Throw the ball and stop the running man.
To handle user events, the <input> object is used. A button was created for each function mentioned above. To display buttons evenly, all buttons are added within a <table> tag.  The controls are shown and described below:
The Start and Stop buttons call the Start() and Stop() JavaScript functions respectively. As the name implies these buttons are used to start and stop the running man.
The Faster and Slower buttons call the Fast() and Slow() JavaScript functions respectively. These functions will reduce and increase the animation interval time; making the running man go faster or slower. The interval time is displayed in a <span> tag.
The Insert car button calls the CarCase() JavaScript function. This function includes a jumping car, and gives the impression that the running man is being chased. When the car is added the running man automatically speeds up. To stop the car chase, users must click the Insert car button.
The Bounce ball button calls the BounceBall() JavaScript function. This function throws an obstacle (bouncing ball) that stops the running man. To remove the bouncing ball, users must click the Bounce ball button.

CSS annotations

Amongst all properties in my CSS file, I would like to focus and describe two in particular:
  • The Position
and
  • The Z-Index

The Position

To be able to position images in their correct location and make them overlap each other, I used the Position CSS property. By default in HTML, all objects float; will not overlap each other. The following shows an example of floating images:
To ignore floating and position an images at a specific location, the absolute value should be used. The following code shows an example that includes the absolute value:
When using the absolute value, the top and left CSS properties can be used to specify the object exact location.

The Z-Index

The Z-Index property enables you to specify the display order when objects overlap each other. For example, in the running man task, two images overlap each other; the fence and the running man.
To specify how objects should be placed in my animation, I included the Z-Index property in the CSS style as shown below:
The greater is the Z-Index value, the more visible is the object. So in this case the running man will be in front of the fence.

The JavaScript code

The Running Man

The animation is made up of six different images. Using the JavaScript setInterval() method, the images will continue to iterate until a clearInterval() is called.
When creating animations that include images, it is recommended to load the images in memory at start up. This process is called Caching. If the images are not cached, the browser will attempt to download the image on the client side when needed; making the animation slower.
The following code shows the images used for the running man being cached:
At line 7, an array is declared to store all image objects. In lines12 and 13 a for loop is used to assign a new Image object to each array item. In lines 16 to 21, each image source path is configured using the src property.
At line 5 a variable that stores the current image being displayed is declared and assigned the 0 value (Arrays start at 0). The variable declared at line 6 is used to store the setInterval() object.
The following code checks the current image displayed and moves to the next image:
This function will first check the currRunner value; this indicates the current image displayed. If the current image is 5 the function will set the currRunner to 0 to re-start from the first image. If the current image is not 5 the currRunner is incremented by one, thus moving to the next image. In lines 72 to 75, the same algorithm is used to display the moving fence. At lines 77 and 78, the man and fence <img> tags are updated with the new images.
The Start() function is called when the user clicks the Start button.
At line 83, the clearInterval() is used to prevent a user from starting an interval that is already running.
At line 84 the setInterval() is created and stored in variable startRunning. The interval, calls the MoveNextStep() function at an interval speed stored in a global variable (speed). Storing the speed in a global variable is required, because this enables you to increase and reduce the interval speed from any function.
To enable the user to view the current speed, at line 85 the UpdateSpeed() is called. This updates the innerHTML() in the <span> tag.
Lines 89 and 90, ensures that the bouncing ball is hidden when the user clicks the Start button.
The Stop() function is called when the user clicks the Stop button.
At line 95, the clearInterval() is used to stop the interval stored in startRunning. When the animation stops, the man image is updated (line 96) and the speed is set to 0 (line 97).
Lines 101 to 102 ensures that the car is hidden when the user clicks the Stop button.
The Fast() and Slow() functions are called when the user clicks the Faster and Slower buttons.
First the function checks if the running man animation is started. This is done by checking the value of a flag (isRunning). If the animation is started the speed is decremented or incremented by 10 milliseconds.
These functions also include the algorithm to keep the values between 10 and 200 milliseconds.

The Chasing car

The car chasing animation is very similar to the running man animation. Image objects are saved in an array car[] and the current image is stored in a variable called curcar. The CarCase() function is called when the user clicks the Insert car button. Using the setInterval() method, the MakeCarJump() function is called every 100 milliseconds.
Since the same button is used to start and stop the car chase animation, the function first checks if the animation is started. If the animation is already running, the animation stops and vice versa.
One thing to note in this code is the syntax used to make the car visible. By default the car <img> tag is hidden using style="display:none" in the HTML markup. To make the car visible the syntax in line 139 below is used. On the other hand to hide the car the syntax in line 133 is used.

The bouncing ball

The bouncing ball animation is very similar to the car chasing animation. Image objects are saved in an array ball[] and the current image is stored in a variable called curball. The BounceBall() function is called when the user clicks the Bounce ball button. Using the setInterval() method, the MakeBallBounce() function is called every 130 milliseconds.

The final output

The output of my design is shown in the following video:

Cross Browsers

The running man animation was tested with successful results on the following browsers:
  • Internet Explorer
  • Firefox
  • Google Chrome
  • Safari

Paint.net – Good to have

Paint.net is a photo and image editing application that helped me a lot while modifying the images used in this project. Amongst others I used Paint.net to:
  • Change image colors
  • Resize images
  • Set image transparency
Paint.net is available from http://www.getpaint.net/. 

Conclusion

As time goes by, JavaScript is becoming one of my favourite programming languages. I ‘am very satisfied with the result obtained from this task and in the future I would like to go deeper in the subject.
I recommend trying some online tutorials available at W3Cschools or from Developing Web Application (my course work handbook by Ralph Moseley). Lot of images exist online that can be downloaded and used for free in your animations. Once you learn the basics, it will not take long to create your own JavaScript animation.
Enjoy coding!!!