Change image multiple times
Hi,
Basically my query is i want to have multiple image rollovers working so below is the code where i have 3 images but when i click on the image on web it only shows me 2nd picture but doesnt show 3rd picture.
I want when i do a mouse over on the image it should starts to change again and again until i remove the mouse from the image.
Below is my some sample code.
I would be grateful if somebody help me out.
:confused:
Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
Rollimage = new Array()
Rollimage[0]= new Image(121,153)
Rollimage[0].src = "car1.jpg"
Rollimage[1] = new Image(121,153)
Rollimage[1].src = "car2.jpg"
Rollimage[2] = new Image(121,153)
Rollimage[2].src = "car3.jpg"
function SwapOut(){
for (i=0; i< Rollimage.length; i++)
{
document.Rupert.src = Rollimage[i].src;
}
i++;
return true;
}
function SwapBack(){
document.Rupert.src = Rollimage[0].src;
return true;
}
</SCRIPT>
</HEAD>
<BODY>
<IMG SRC="car1.jpg"
NAME="Rupert"
WIDTH=121
HEIGHT=153
BORDER=0 onmouseover="SwapOut()"
onmouseout="SwapBack()">
</A>
</P>
<p>test</p>
</BODY>
</HTML>
Thanks,
Regards,
So many questions ... so little time ...
Questions:
1. What are the parameters after the new Image() assignment for?
If they are to define the width and height, this is not the way to do it.
You syntax creates an Array with 121x151 elements, which never get assigned!
2. Why the extra i++ at the end of the 'SwapOut()' function?
As far as I can see it is not used anywhere.
Also, try putting a temporary 'alert(msg)' in the loop to make sure
that the image assignment is correct and that it is not happening
so fast that you cannot see the change occur.
3. I don't understand the reference to the 'on click' in the first sentence.
You only check for 'onMouseOver=' and 'onMouseOut=' to occur, not 'onClick='.
Simple Loop to change images
First of all many thanks but I am kind of confused here...
As i just want a simple script in which loop running to change image multiple times when mouse is hovered in...
Thanks,
Regards,