PDA

View Full Version : Looking for a clickable image swap


AshleyQuick
02-10-2003, 09:07 PM
Very similar to a standard mouseover but the user needs to click instead.

Ash

justame
02-11-2003, 01:32 AM
ash...
/me just a has® this copied/pasted/credited n' saved from just a nother® forum member...
jyoung ....posted 08-28-2000 09:38 PM


Check out this example. It might give you some ideas.
<html>
<head>
<title>Image Flip</title>
<script language="JavaScript">
<!--//

ImGage=new Array()
ImGage[0]=" "
ImGage[1]=" "
ImGage[2]=" "
ImGage[3]=" "
Pict=new Array()
Pict[0]="pic0.gif"
Pict[1]="pic1.gif"
Pict[2]="pic2.gif"
Pict[3]="pic3.gif"

var GiF0="0"
var GiF1="0"
var GiF2="0"
var GiF3="0"
for(x=0; x<=100; x=x+1)
{
var gifnum=Math.round(3 * Math.random());
if(ImGage[gifnum] == " ")
{
var gifnm=Math.round(3 * Math.random());
if(Pict[gifnm] != " ")
{
ImGage[gifnum]=Pict[gifnm]
Pict[gifnm]=" "
}
}

}

aClicks=0
bClicks=0
cClicks=0
dClicks=0
function flip(place,imgnam,anum)
{
Image1=new Image(50,50)
Image1.src = ImGage[anum]
if (eval(place+"Clicks")%2==0)
{
document.images[imgnam].src=Image1.src
}
else
{
document.images[imgnam].src="bubble1.gif"
}

}
//-->
</script>

</head>
<body bgcolor="lightgreen">
<center>
<A HREF="#" onclick="flip('a','imageA',0); aClicks++"><IMG SRC="bubble1.gif"
NAME=imageA BORDER=0 WIDTH=75 HEIGHT=75></A>

<A HREF="#" onclick="flip('b','imageB',1); bClicks++"><IMG SRC="bubble1.gif"
NAME=imageB BORDER=0 WIDTH=75 HEIGHT=75></A>

<A HREF="#" onclick="flip('c','imageC',2); cClicks++"><IMG SRC="bubble1.gif"
NAME=imageC BORDER=0 WIDTH=75 HEIGHT=75></A>

<A HREF="#" onclick="flip('d','imageD',3); dClicks++"><IMG SRC="bubble1.gif"
NAME=imageD BORDER=0 WIDTH=75 HEIGHT=75></A>
</CENTER>
</body>
</html>

Skyzyx
02-11-2003, 01:36 AM
There's the one posted here: http://www.codingforums.com/showthread.php?s=&threadid=11673

You'd just need to change the onmouseover to onclick.