lundi 20 avril 2015

How to have 2 same functions in Javascript for 3 different images?

This is the code that I found online from someone and used it on my own HTML code.

<script type="text/javascript">// <![CDATA[
var image=new Array("/Users/ghanimbakhit/Desktop/HTML Project/images/rock.jpg",
"/Users/ghanimbakhit/Desktop/HTML Project/images/rock2.jpg",
"/Users/ghanimbakhit/Desktop/HTML Project/images/rock3.jpg");


var timeout={};
function stopIt(){
clearTimeout(timeout);
}
function changeimage(dvX){
var dvi=document.getElementById(dvX);
if(!dvi.count || dvi.count == image.length )
dvi.count=0;
dvi.src=image[dvi.count];
dvi.alt=image[dvi.count];
dvi.count=dvi.count+1;
timeout=setTimeout('changeimage("'+dvX+'")',3500);
}
// ]]></script>

And this is the body

<body onload="changeimage('changer')">
<div style="position:absolute;top: 600px"  ><img width="350" src="t1 alt="Rock Climbing"  id="changer"/></div>

This code is used to automatically change images in a few seconds, and I chose it so for some images "rock,rock2,rock3". I have 2 more images that I want the same function to be done with. How can I do that without overriding the above code? Im new to Javascript.

If anything more is needed please do notify me, I have to submit this in 3 hours. Thank you

1 commentaire:

  1. Paddy Power Casino UK Review | Bonus & Welcome Bonus
    Read septcasino our Paddy Power Casino Review including games, customer support, banking methods & exclusive promotions. 1xbet Claim your welcome bonus now! Rating: 2.6 · ‎Review by Giancarlo Stanton deccasino

    RépondreSupprimer