How do you list jquery rollover pngs vertically

195 views Asked by At

I would like to list the rollovers vertically and I got such a quick reply I thought I would try again.

The script I have is:

$(document).ready(function()
{
$("img.b").hover(
function() {
$(this).stop().animate({"opacity": "1"}, "slow");
},
function() {
$(this).stop().animate({"opacity": "0"}, "slow");
});

});

And the CSS for it is as follows:

div.fadehover {
    position: relative;
    }

img.b {
    position: absolute;
    left: 0;
    top: 0;

        z-index: 10;
    opacity: 0;
    filter: alpha(opacity=0);
    }

And the body code is:

<div class="fadehover">
<a href=""><img src="portfolio_a.png" alt="" class="a" />
<img src="portfolio_b.png" alt="" class="b" /></a>

</div>

What I want to do is take that functionality and blend it into a vertical menu. I have made a basic swap image one from Dreamweaver. I would like to replace it with the previous code. When I plug them in using a table The div layers appear to hang overtop of one another. Here is the limited Dreamweaver code for the page I would like to replace:

<script type="text/javascript"> 
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
//-->
</script>

... and the body code is:

<div id="menu">  
  <table border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','portfolioa','portfolio_b.png',1)" onmouseover="MM_nbGroup('over','portfolioa','portfolio_b.png','portfolio_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="portfolio_a.png" alt="Portfolio" name="portfolioa" width="221" height="39" border="0" id="Portfolio" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','cginewa','cgi_new_b.png',1)" onmouseover="MM_nbGroup('over','cginewa','cgi_new_b.png','cgi_new_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="cgi_new_a.png" alt="CGI | New" name="cginewa" width="221" height="40" border="0" id="CGINew" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','cgiarchivea','cgi_archive_b.png',1)" onmouseover="MM_nbGroup('over','cgiarchivea','cgi_archive_b.png','cgi_archive_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="cgi_archive_a.png" alt="CGI | Archive" name="cgiarchivea" width="221" height="39" border="0" id="CGIArchive" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','webdesigna','webdesign_b.png',1)" onmouseover="MM_nbGroup('over','webdesigna','webdesign_b.png','webdesign_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="webdesign_a.png" alt="Webdesign" name="webdesigna" width="221" height="38" border="0" id="Webdesign" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','mediaa','media_b.png',1)" onmouseover="MM_nbGroup('over','mediaa','media_b.png','media_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="media_a.png" alt="Media" name="mediaa" width="221" height="39" border="0" id="Media" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','identitya','identity_b.png',1)" onmouseover="MM_nbGroup('over','identitya','identity_b.png','identity_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="identity_a.png" alt="Identity" name="identitya" width="221" height="40" border="0" id="Identity" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','aboutmea','aboutme_b.png',1)" onmouseover="MM_nbGroup('over','aboutmea','aboutme_b.png','aboutme_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="aboutme_a.png" alt="About Me" name="aboutmea" width="221" height="36" border="0" id="AboutMe" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','academica','academic_b.png',1)" onmouseover="MM_nbGroup('over','academica','academic_b.png','academic_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="academic_a.png" alt="Academic" name="academica" width="221" height="40" border="0" id="Academic" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','professionala','professional_b.png',1)" onmouseover="MM_nbGroup('over','professionala','professional_b.png','professional_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="professional_a.png" alt="Professional" name="professionala" width="221" height="38" border="0" id="Professional" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','contacta','contact_b.png',1)" onmouseover="MM_nbGroup('over','contacta','contact_b.png','contact_b.png',1)" onmouseout="MM_nbGroup('out')"><img src="contact_a.png" alt="Contact Me" name="contacta" width="221" height="40" border="0" id="Contact" onload="" /></a></td> 
    </tr> 
    <tr> 
      <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','linksa','links_b.png',1)" onmouseover="MM_nbGroup('over','linksa','links_b.png','links_a.png',1)" onmouseout="MM_nbGroup('out')"><img src="links_a.png" alt="Links" name="linksa" width="221" height="41" border="0" id="Links" onload="" /></a></td> 
    </tr> 
  </table> 
</div> 

The webpage I am designing this menu for can be seen here: http://www.kaimeramedia.com/derek/Website/Main_New.html

1

There are 1 answers

2
Jasper On BEST ANSWER

You can do the same thing as in your old question: How do I make a rollover using png and jquery?. The only difference is you need to copy/paste the HTML into the table cells and change the image sources to reflect the different navigation items. I recommend going with best-practices and not using a table for your layout. You can stack divs on top of each other like this:

<div class="hover-container">
    <div class="fadehover">...</div>
    <div class="fadehover">...</div>
    <div class="fadehover">...</div>
    <div class="fadehover">...</div>
</div>

Now you can position this wherever you like by altering the CSS of the div.hover-container:

.hover-container {
    position: relative;
    width: 250px;
}

Here is a jsfiddle: http://jsfiddle.net/jasper/CyJXD/1/

Note that you need to apply a height to the div.fadehover as its contents are absolutely positioned, giving it a height of zero (if you don't give a height the different navigation items will appear on top of each other).