Jump to Navigation

062 - Change from image1 to image2 by mouse

This is sample codes, when a user clicks on the image, it changes from pic_1.gif to pic_2.gif.

Example:


<script language="Javascript">
<!--
myImage=new Array(2)
for (var i=0;i<2;i++){
myImage[i]=new Image()
myImage[i].src="pic_"+(i+1)+".gif"
}
currentImage=0;   
function changePic(){
switch(currentImage){
case 0: document.my_pic.src=myImage[1].src;
currentImage=1;
break;
case 1: document.my_pic.src=myImage[0].src;
currentImage=0;
break;
}
}
//-->
</script>
<img src=”pic_1.gif” name=”my_pic” onClick=”changePic()”>

 

JavaScript:


Main menu 2

Story | by Dr. Radut