English
German

JavaScript Animation

JavaScript Animation

It is possible to use JavaScript to create animated images.

The trick is to let a JavaScript change between different images on different events.

In the following example we will add an image that should act as a link button on a web page. We will then add an onMouseOver event and an onMouseOut event that will run two JavaScript functions that will change between the images.


The HTML Code

The HTML code looks like this:

<a href="http://www.hiscript.com" target="_blank">
<img border="0" alt="Visit Hi Script!" src="b_pink.gif" id="b1"
onmouseOver="mouseOver()" onmouseOut="mouseOut()" /></a>

Note that we have given the image an id, to make it possible for a JavaScript to address it later.

The onMouseOver event tells the browser that once a mouse is rolled over the image, the browser should execute a function that will replace the image with another image.

The onMouseOut event tells the browser that once a mouse is rolled away from the image, another JavaScript function should be executed. This function will insert the original image again.


The JavaScript Code

The changing between the images is done with the following JavaScript:
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="r_red.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="r_blue.gif";
}
</script>

The function mouseOver() causes the image to shift to "r_red.gif".

The function mouseOut() causes the image to shift to "r_blue.gif".


Example:

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
</head>

<body>
<a href="http://www.hiscript.com" target="_blank">
<img border="0" alt="Visit Hi Script!" src="b_pink.gif" id="b1"
onmouseover="mouseOver()" onmouseout="mouseOut()" /></a>
</body>
</html>


Javascript Tutorial,JavaScript Animation, JavaScript Animation example, learn JavaScript Animation,explain example JavaScript Animation online free training Javascript Tutorial, Javascript Tutorial example, learn JavaScript Animation, online tutorial, download tutorial, Javascript Tutorial books, Javascript Tutorial videos, live videos Javascript Tutorial, learn Javascript Tutorial, Javascript Tutorial topic JavaScript Animation, live training Javascript Tutorial, download free tutorial