Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    113
    Thanks
    27
    Thanked 0 Times in 0 Posts

    problem with rollover

    I'm having a little trouble getting this script to work. It should create a nice 3-state rollover for my link images. I know how to do more basic rollovers, but my understanding is that this one will allow me to add images later without changing my script at all. Here's the script:

    Code:
    window.onload = rolloverInit;
    
    function rolloverInit() {
    	for (var i=0; i<document.images.length; i++) {
    		if (document.images[i].parentNode.tagName == "A") {
    			setupRollover(document.images[i]);
    		}
    	}
    }
    
    function setupRollover(thisImage) {
    	thisImage.outImage = new Image();
    	thisImage.outImage.src = thisImage.src;
    	thisImage.onmouseout = rollOut;
    
    	thisImage.overImage = new Image();
    	thisImage.overImage.src = "assets/images/navigation/" + thisImage.id + "_on.gif";
    	thisImage.onmouseover = rollOver;
    
    	thisImage.clickImage = new Image();
    	thisImage.clickImage.src = "assets/images/navigation/" + thisImage.id + "_click.gif";
    	thisImage.onmousedown = rollClick;	
    }
    
    function rollOut() {
    	this.src = this.outImage.src;
    }
    
    function rollOver() {
    	this.src = this.overImage.src;
    }
    
    function rollClick() {
    	this.src = this.clickImage.src;
    }

    and the HTML:

    Code:
    <div id="topLinks"><a href="bio.html"><img id="bio" src="assets/images/navigation/bio_off.png" /></a>
    It's not in the code above, but the page is properly linked to the external script page. When I test it in Safari, the initial image appears, but I get the "?" box when I rollover. In Firefox, nothing happens when I rollover.

    I have double checked the location of the files, and they look good.
    Last edited by mightypants; 06-13-2008 at 09:50 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2008
    Posts
    113
    Thanks
    27
    Thanked 0 Times in 0 Posts
    figured out the problem.

    ".gif" in the script should have been ".png"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •