0

我想垂直列出翻转,我得到了如此快速的回复,我想我会再试一次。

我的脚本是:

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

});

它的CSS如下:

div.fadehover {
    position: relative;
    }

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

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

正文代码是:

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

</div>

我想要做的是采用该功能并将其融合到垂直菜单中。我从 Dreamweaver 制作了一个基本的交换图像。我想用以前的代码替换它。当我使用表格将它们插入时 div 层似乎彼此重叠。这是我要替换的页面的有限 Dreamweaver 代码:

<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>

...而正文代码是:

<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> 

我正在设计这个菜单的网页可以在这里看到:http ://www.kaimeramedia.com/derek/Website/Main_New.html

4

1 回答 1

1

您可以执行与旧问题相同的操作:如何使用 png 和 jquery 进行翻转?. 唯一的区别是您需要将 HTML 复制/粘贴到表格单元格中并更改图像源以反映不同的导航项。我建议采用最佳实践,而不是使用表格进行布局。您可以像这样将 div 堆叠在一起:

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

现在,您可以通过更改 CSS 的 CSS 将其放置在您喜欢的任何位置div.hover-container

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

这是一个jsfiddle:http: //jsfiddle.net/jasper/CyJXD/1/

请注意,您需要对它应用高度,div.fadehover因为它的内容是绝对定位的,使其高度为零(如果您不给出高度,则不同的导航项将出现在彼此的顶部)。

于 2011-11-08T22:52:34.663 回答