Javascript Rollover Help

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I need a javascript for a disjoint rollover ASAP. Can anyone help me?

All its gotta do, is when you mouseover one image, anotther image will change. Thanks!
 

teknodude

Member
Apr 11, 2002
186
0
0
I don't quite know what you mean by a "disjoint" rollover, but I think I get what you want. Here's some example JavaScript and HTML code that should show you how to achieve what you want:

---------------------------------------

<script language="JavaScript">
<!--

// You can remove the lines with two slashes at the start as they are only comments

// This part of the code loads the rollover images
if (document.images) {

image2_on = new Image();
image2_on.src = "image2_on.gif";

image2_off = new Image();
image2_off.src = "image2_off.gif";

}

// This function switches the images
// The parameters are passed in the form of 'image name', 'image src'
function changeImages() {
if (document.images) {
for (var y=0; y < changeImages.arguments.length; y+=2) {
document[changeImages.arguments[y]].src = eval(changeImages.arguments[y+1] + ".src");
}
}
}

//-->
</script>

<img src="image1.gif" onmouseover="changeImages('image2', 'image2_on')" onmouseout="changeImages('image2', 'image2_off')">

<img src="image2_off.gif" name="image2">

---------------------------------------

The JavaScript goes between the <head></head> tags of your page and the HTML code for the images obviously goes wherever in between your <body></body> tags (not necessarily together).

Hope that helps you - please post back if you need any more help :)

teknodude

[edit]
check out a demo of this code in action at http://www.gplenderleith.freeserve.co.uk/demos/twopartrollover.htm
[/edit]
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
Disjoint meaning when you move the mouse over Image #1, Image #2 changes.

Will above scriptwork?
 

teknodude

Member
Apr 11, 2002
186
0
0
Yes, the above script will do exactly what you require - check out the demo at the URL above :)

teknodude
 

earthman

Golden Member
Oct 16, 1999
1,653
0
71
You can also do this with layers, changing the content of a div and have it reset on mouseout.
 

teknodude

Member
Apr 11, 2002
186
0
0
Originally posted by: earthman
You can also do this with layers, changing the content of a div and have it reset on mouseout.

Err...yeah...but I don't think that will achieve what Superwormy wants.

teknodude