Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rollovers

Status
Not open for further replies.

wuzzle

Programmer
Dec 20, 2000
75
CA
Here is my script:

<script>
var homeOff = new Image();
var homeOn = new Image();

homeOff.src = &quot;images/menu_homeOff.gif&quot;;
homeOn.src = &quot;images/menu_homeOn.gif&quot;;

function roll1(){document.images[0].src=&quot;images/menu_homeOn.gif&quot;}
function roll2(){document.images[0].src=&quot;images/menu_homeOff.gif&quot;}
</script>

and here is where the function is called:

<a href=&quot;home.htm&quot; onMouseOver=&quot;roll1()&quot; onMouseOut=&quot;roll2()&quot;><img src=&quot;images/menu_homeOff.gif&quot; border=0></a>

The problem is, if I place an image above the rollover image (above), and type it like this:

<img src=&quot;images/header.gif&quot;><br>
<a href=&quot;home.htm&quot; onMouseOver=&quot;roll1()&quot; onMouseOut=&quot;roll2()&quot;><img src=&quot;images/menu_homeOff.gif&quot; border=0></a>

If I mouse over the menu_homeOff.gif image, the header.gif image changes. When I delete the header image, menu_homeOff.gif changes to menu_homeOn.gif when I mouse over it, like it's supposed to.

What can I do to fix this? Thanks.
 
I'd say it's an indexing problem - When you mouseOver menu_HomeOff.gif - roll1() is called which changes the src of the first image on the page.

Images are put in the array in the order they appear in the code.

When you put the header above menu_homeOff - then you are now saying that the header is images[0]- because it is the first one created on the page.

If you were to either change the index to '1' - it will work, or you could name the image, and reference it that way.

function roll1(){document.images[1].src=&quot;images/menu_homeOn.gif&quot;


You have preloaded these images but not used them? To use them change our function like:

function roll1(){document.images[1].src = homeOn.src;


NOTE: These preloaded images are not included in the document.images array

also if you named the image you could access it like:
document.images['name'].src...
&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top