Menu
Hi is there a simpel function for swapping an image onClick. And then when the image is swapped and you Click on the same item it restores again.
Thanks in advance
[code=php]
<body bgcolor="#999999">
<script>
var q=0;
function swapImg (imgName)
{
if(q==0){
document.images[imgName].src = eval('imgName + ".jpg"')
q++
}
else{
document.images[imgName].src = eval('imgName + ".gif"')
q--
}
</script>
<a href="javascript:swapImg('01')"><img src="img/01.gif" name="contact" width="700" height="359"></a>
</body>[/code]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
var q=0;
var root='img/';
function swapImg(ima){
nr = ima.getAttribute('src').split('/');
nr = nr[nr.length-1].split('.')[0];
if(q==0){ima.setAttribute('src',root+nr+'.jpg');q++;}
else{ima.setAttribute('src',root+nr+'.gif');q--;}
}
</script>
</head>
<body>
<img style="cursor:pointer" src="img/01.gif" name="contact" width="700" height="359" onclick="swapImg(this)">
</body>
</html>
[/code]
[CODE]
var namesVec = new Array("myfirstimage.gif", "secondimage.jpg");
var root='theme_images/';
function swapImg(ima){
// divides the path
nr = ima.getAttribute('src').split('/');
// gets the last part of path, ie name
nr = nr[nr.length-1]
// former was .split('.')[0];
if(nr==namesVec[0]){ima.setAttribute('src',root+namesVec[1]);}
else{ima.setAttribute('src',root+namesVec[0]);}
}
[/CODE]
[CODE]
//___________________________________________________________
// Swap Image Script ________________________________________
//___________________________________________________________
var namesVec = new Array("switch_off.gif", "switch_on.gif");
var root ='images/';
function swapImg(ima){
// divides the path
nr = ima.getAttribute('src').split('/');
// gets the last part of path, ie name
nr = nr[nr.length-1]
// former was .split('.')[0];
if(nr==namesVec[0]){ima.setAttribute('src',root+namesVec[1]);}
else{ima.setAttribute('src',root+namesVec[0]);}
}
[/CODE]
[code=html]
<img src="images/switch_off.gif" width="150" height="229" border="0" onclick="swapImg();" />
[/code]
[CODE]
var namesVec = new Array("arrowdcrimsonright.gif", "arrowdcrimsondown.gif");
var root='theme_images/';
function togglepics(image,showorhide){
if (showorhide=="show") {image.setAttribute('src',root+namesVec[0]);}
if (showorhide=="hide") {image.setAttribute('src',root+namesVec[1]);}
nr = image.getAttribute('src').split('/');
nr = nr[nr.length-1]
if(nr==namesVec[0]){image.setAttribute('src',root+namesVec[1]);}
else{image.setAttribute('src',root+namesVec[0]);}
}[/CODE]
[CODE]
<button
class="button"
onclick="togglepics(this.firstChild, 0)"><img src="./theme_images/arrowdcrimsonright.gif" height="14"></button>[/CODE]
[code=html]
<img src="images/switch_off.gif" width="150" height="229" border="0" onclick="swapImg();" />
[/code]
Any help would be great!
Cheers,
G[/QUOTE]
[code=html]onclick="swapImg(this)"[/code]
instead of [code=html]onclick="swapImg();"[/code]
0.1.9 — BETA 5.28