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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -