The JavaScript code you provide has some problems as it used to redefine the functions. The way you've invoked the functions like mouseOver, mouseDown seems to be logically incorrect for me.
Whenever you create an img object you can do it in a number of manner. Either by providing the width or/and height of the img element as well as without providing any of the values
For eg:
var img = new Image(100,900);
In this case 100 represent the width and 900 the height.
Another method is
var img = new Image()
This is also a valid method
I've changed the code you've provided mostly and made it work with multiple slideshow in a page possible. Have a look at the demo page furnished below
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style type="text/css">
</style>
<script type="text/javascript">
//Store your images in the following order Over image,Original image, Down image otherwise adjust the alogorithm according to the order.
// var imgNames = ["Images/ajaxianOver.jpg", "Images/ajaxianOriginal.jpg", "Images/ajaxianDown.jpg", "Images/atpTennisOver.jpg", "Images/atpTennisOriginal.jpg", "Images/atpTennisDown.jpg"];
var imgNames = ["1.gif", "2.gif", "3.gif", "4.gif", "5.gif", "6.gif"];
var imgArr = new Array(imgNames.length);
for (var i = 0; i < imgArr.length; i++) {
var img = new Image();
img.src = imgNames[i];
imgArr[i] = img;
}
function mouseOver(intImgIndex){
var idx = intImgIndex * 3;
document.images[intImgIndex].src = imgArr[idx].src;
}//end mouseOver()
function mouseOut(intImgIndex){
var idx = intImgIndex * 3;
document.images[intImgIndex].src = imgArr[idx + 1].src;
}//end mouseOut()
function mouseDown(intImgIndex){
var idx = intImgIndex * 3;
document.images[intImgIndex].src = imgArr[idx + 2].src;
}//end mouseDown()*/
</script>
</head>
<body>
<div>
<a href="#" onMouseOver ="javascript:mouseOver(0);" onMouseOut ="javascript:mouseOut(0);" onMouseDown ="javascript:mouseDown(0);" onMouseUp ="javascript:mouseOver(0);"><img src="2.gif" border="0"/></a>
</div>
<br/>
<br/>
<div>
<a href="#" onMouseOver ="javascript:mouseOver(1);" onMouseOut ="javascript:mouseOut(1);" onMouseDown ="javascript:mouseDown(1);" onMouseUp ="javascript:mouseOver(1);"><img src="5.gif" border="0"/></a>
</div>
</body>
</html>
Each image element has 3 images associated with it one mouseover image, one original image and one mousedown image. The order in which I've inserted the image names in the JS array is the following moueover_image, original_image,mousedown_image.
I hope the code is self explanatory but if you have any problems with it please let me know
Bookmarks