html - Animated gallery JavaScript -


i trying build function change pictures on "onmouseover" event without page refresh, doesn't work.

<script>    = 0;    function foto_start() {  	x = ["image2", "image3", "image4"];  	y = document.getelementbyid("1").src;	   	      //loop replace in string "image1" on "image2", "image3" ...  	while(1) {	  		z = y.replace("image1", x[i]);  		  		settimeout(new_image(), 1000);  		          //if last element in array, set = 0 else increase  		if(x[i] == "image4")  			i = 0;  		else  			i++;  	}  }    function new_image() {  	document.getelementbyid("1").src = z;  }    function foto_stop() {  	document.getelementbyid("1").src = "http://example.com/image1.jpg";  }    </script>
// element html modify  <img id="1" onmouseover="foto_start()" onmouseout="foto_stop()" src="http://example.com/image1.jpg" />

no need complicated stuff, can put parameter in foto_start() method:

function foto_start(imagesrc){     document.getelementbyid('1').src=imagesrc; }  <img id="1" onmouseover="foto_start('http://example.com/image2.jpg')" onmouseout="foto_stop()" src="http://example.com/image1.jpg" /> 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -