Jump to content

Img Rollover not working!


Recommended Posts

Hey!Ok so I have a javascript that basically changes the image when the cursor is on it. Simple right? Well not for me it seems. Usually it is but it seems like it's not working today...First when I load the page the image is there and then on hover you only see the alt and the X in the corner. no pop-ups.Script

<script type="text/javascript">	<!-- // 	//if browser is compatible	if (document.images) {   //preload images   //base image   a= new Image(91,40);   a.src= 'topnav-home.jpg';  //hover or rollover image   aover= new Image(91,40);   aover.src= 'topnav-home-over.jpg';    function myOn(myImgName) {  	 document[myImgName].src=eval(myImgName+ 'over').src;   } 	   function myOut(myImgName) {  	 document[myImgName].src=eval(myImgName).src;   } 	}	//-->	</script>

HTML

<li><a href="index.htm"><img src="images/topnav-home.jpg" name="a" height="40" width="91" alt="Home" onmouseover="myOn('a')" onmouseout="myOut('a')" /></a></li>

For testing purposes I have changed the html name of the img to "a" to eliminate chances of typos. I have double and triple and quattriple checked the image file name and they are exact. I have copy pasted them to make sure.I have taken this code from 2 previous projects I've done and it worked perfectly.Thanks!

Link to post
Share on other sites

Dude it works fine :) If i use two internet images then it works fine, you must be using incorrect file paths or something...

<head><script type="text/javascript"><!-- // //if browser is compatibleif (document.images) {  //preload images  //base image  a= new Image(91,40);  a.src= 'http://www.google.co.uk/intl/en_uk/images/logo.gif'; //hover or rollover image  aover= new Image(91,40);  aover.src= 'http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif';  function myOn(myImgName) {   document[myImgName].src=eval(myImgName+ 'over').src;  }   function myOut(myImgName) {   document[myImgName].src=eval(myImgName).src;  } }//--></script></head><body><li><a href="index.htm"><img src="http://www.google.co.uk/intl/en_uk/images/logo.gif" name="a" height="40" width="91" alt="Home" onmouseover="myOn('a')" onmouseout="myOut('a')" /></a></li></body>

Link to post
Share on other sites

It must be somekind of bug with the page probably... I have checked so many times the paths and filenames, trust me it's fine. I guess I'll play around with my code and see.

Link to post
Share on other sites

I got it.... What a ###### error lol. I forgot you needed the "images/" path in there.I'll post my project in the show off the sites thread. It's very hot! :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...