| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 598 人关注过本帖
标题:[求助]下拉菜单问题
只看楼主 加入收藏
qw306
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-9-8
收藏
 问题点数:0 回复次数:2 
[求助]下拉菜单问题


:( 想弄这个菜单,但是有个问题,就是这个子菜单是透明的..二级,三级菜单都是个透明背景.我希望的是能够填充一种颜色去..望知道怎么修改的帮帮手..下面是源码,附件也是这个的源码.






<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>菜单</title>
</head>
<body>
<script language="JavaScript">
//----------------------菜单属性设置--------------------------
var MHeight = 20; //菜单高度
var MWidth = 80; //菜单宽度 
var MColor = "#000000";//菜单颜色
var MFColor = "#000000"; //字体颜色
var MOverBG = "#333333"; //鼠标经过时的背景颜色
var MOverFC = "#ffffff"; //鼠标经过时的字体颜色

var menuSpeed = 50; //---------- 菜单显示速度 ------------//

var alphaStep = 30; //---------- Alpaha 变化 度 -----------//

var str;
/*--------------创建菜单对象----------*/
var oldTR = null; //控制鼠标经过时背景颜色变量
var SubMenuList = new Array;
var NowSubMenu ="";
var M = 0, MN;

function Menu(objName)
{
this.name = objName;
this.addMenu = addMenu;


document.write("<table id="+objName+" cellpadding=0 cellspacing=0 style='position:absolute;left:0;top:0;border:1px solid "+MColor+";font-size:12px;visibility:hidden;filter:Alpha(Opacity=100);'></table>");

this.length = 0;
}

function addMenu(Word,Link,MChild)
{
var row,cell;
var oBody = document.getElementById(this.name);
var tbody = oBody.childNodes[0];
oBody.appendChild(tbody);

row = document.createElement("TR");
tbody.appendChild(row);

row.id = this.name+"_"+this.length;
row.attachEvent("onmouseover",MOver(row,MChild)); //菜单变色
row.attachEvent("onclick",MClick(row));
row.style.cursor = "hand";

for(i=0;i<4;i++)
{
cell = document.createElement("TD");
row.appendChild(cell);
}
with(row)
{
cells(0).style.backgroundColor = MColor;
cells(0).style.pixelWidth = "4";

cells(1).style.pixelHeight = MHeight;
cells(1).style.pixelWidth = MWidth;
cells(1).style.textAlign = "left";
cells(1).innerHTML = "<a href="+Link+"></a>"+Word;

if(MChild)
cells(2).innerHTML = "<img src=arrows.gif>";
else
cells(2).innerHTML = " ";

cells(3).innerText = " ";
}

this.length++;

}

function MClick(obj)
{
return mc;
function mc()
{
if(obj.cells(1).all.tags("A").length>0)
{
obj.cells(1).all.tags("A")(0).click();
}

}
}


function MOver(obj,isShow)
{
return mo;
function mo()
{
if(isShow)
ShowMenu(isShow,0,obj);

else
{
NowSubMenu=obj.parentElement.parentElement.id;
HideMenu(1);
}
if(oldTR)
with(eval(oldTR).style)
{
backgroundColor = "";
color = MFColor;
}
obj.style.backgroundColor = MOverBG;
obj.style.color = MOverFC;
oldTR = obj.id;
}
}

function ShowMenu(Menu,isTop,OldMenu)
{
if(isTop)
{ M = 1;
MN = Menu;
NowSubMenu = "";
HideMenu(1);
SubMenuList[0] = Menu;
var Menu = document.getElementById(Menu);
var EventObj = event.srcElement;
var ET = EventObj.offsetTop, EH = EventObj.offsetHeight, EL = EventObj.offsetLeft;
var BH = document.body.clientHeight, BT = document.body.scrollTop;
while(EventObj=EventObj.offsetParent){ET += EventObj.offsetTop;EL += EventObj.offsetLeft;}

/*window.status="ET:="+ET+"EH:="+EH+"EL:="+EL
+ "BH="+BH+"BT="+BT;*/

if(BH+BT-ET-EH>=Menu.offsetHeight)
Menu.style.pixelTop = ET+EH;
else
Menu.style.pixelTop = (ET-BT>=Menu.offsetHeight)? ET-Menu.offsetHeight : BT;

Menu.style.pixelLeft = EL;

Menu.style.visibility = "visible";

alphaing = setInterval("ShowAlpha('"+Menu.id+"',"+alphaStep+")",menuSpeed);
}
else
{


var Menu = document.getElementById(Menu);
var topobj = OldMenu.parentElement.parentElement;

NowSubMenu = topobj.id;

HideMenu(1);
if(MN!=NowSubMenu){M++;MN=NowSubMenu;}
SubMenuList[M]=Menu.id;


var ET = topobj.offsetTop, EH = topobj.offsetHeight, EL = topobj.offsetLeft, EW = topobj.offsetWidth;
var BH = document.body.clientHeight, BT = document.body.scrollTop ,BW=document.body.clientWidth;
while(topobj=topobj.offsetParent){ET += topobj.offsetTop;EL += topobj.offsetLeft;}

if(BH+BT-ET-OldMenu.offsetTop>=Menu.offsetHeight)
Menu.style.pixelTop = ET + OldMenu.offsetTop;
else
Menu.style.pixelTop = (ET+OldMenu.offsetTop+OldMenu.offsetHeight >=Menu.offsetHeight)? ET+OldMenu.offsetTop+OldMenu.offsetHeight-Menu.offsetHeight :BT;

if(BW-EL-EW>=Menu.offsetWidth)
Menu.style.pixelLeft = EL + EW;
else
Menu.style.pixelLeft = (BW>=Menu.offsetWidth)?EL-Menu.offsetWidth:0;
Menu.style.visibility = "visible";
if(Menu.alphaing)clearInterval(Menu.alphaing);
Menu.alphaing = setInterval("ShowAlpha('"+Menu.id+"',"+alphaStep+")",menuSpeed);
}

}

function HideMenu(num)
{
var themenu="";
if (num==1) themenu=NowSubMenu;

for(var i=SubMenuList.length-1;i>=0;i--)
{
if(SubMenuList[i]&&SubMenuList[i]!=themenu)
{
// document.getElementById(SubMenuList[i]).alphaing = setInterval("HideAlpha('"+SubMenuList[i]+"',"+alphaStep+")",menuSpeed);

document.getElementById(SubMenuList[i]).style.visibility ="hidden";
document.getElementById(SubMenuList[i]).filters.Alpha.Opacity =100;
SubMenuList[i] = null;
}
else
if (SubMenuList[i]==NowSubMenu)return;
}
NowSubMenu="";
}

function ShowAlpha(obj,num)
{
var obj = document.getElementById(obj);

if(obj.filters.Alpha.Opacity<100)
{ obj.filters.Alpha.Opacity += num;}
else
{
clearInterval(obj.alphaing);
obj.filters.Alpha.Opacity = 100;
obj.alphaing = false;
}

}


function document.onclick()
{HideMenu();}
</script>
<style type="text/css">
<!--
body {
background-color: #999999;
}
-->
</style></head>
<body >

<script>
var TM = new Menu("TM");
TM.addMenu("你好","http://www.baidu.com","TMC");
TM.addMenu("你好","http://www.baidu.com","TMC1");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");
TM.addMenu("你好","http://www.baidu.com");

var TMC1 = new Menu("TMC1");
TMC1.addMenu("你好","http://www.baidu.com");
TMC1.addMenu("你好","http://www.baidu.com");
TMC1.addMenu("你好","http://www.baidu.com");
var TMC = new Menu("TMC");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com");
TMC.addMenu("你好","http://www.baidu.com","TMCC");
var TMCC = new Menu("TMCC");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
TMCC.addMenu("你好","http://www.baidu.com");
var TM3 = new Menu("TM3");
TM3.addMenu("你好","http://www.baidu.com");
TM3.addMenu("你好","http://www.baidu.com","TM4");
var TM4 = new Menu("TM4");
TM4.addMenu("你好","http://www.baidu.com");
TM4.addMenu("你好","http://www.baidu.com");
TM4.addMenu("你好","http://www.baidu.com","TM6");
TM4.addMenu("你好","http://www.baidu.com","TM5");
var TM5 = new Menu("TM5");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
TM5.addMenu("你好","http://www.baidu.com");
var TM6 = new Menu("TM6");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");
TM6.addMenu("你好","http://www.baidu.com");

var TM = new Menu("TM7");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");
TM.addMenu("我也好","http://www.baidu.com");

</script>
<table width="768" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr>
<td height="20" >&nbsp;<a href='javascrpt:;' onMouseOver="ShowMenu('TM',1)">菜单一</a></td>
<td>&nbsp; <a href='javascrpt:;' onMouseOver="ShowMenu('TM3',1)">菜单一</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#" onMouseOver="ShowMenu('TM3',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
<td><a href="#"onMouseOver="ShowMenu('TM4',1)">sfsfs</a></td>
</tr>

</table>
</body>
</html>





yoigUFsb.rar (2.95 KB) [求助]下拉菜单问题


[此贴子已经被作者于2007-2-6 17:23:01编辑过]

搜索更多相关主题的帖子: 菜单 
2007-02-06 16:50
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
置顶帖里面好像有,可以我也不会.

我的网站 http://www.
2007-02-06 17:30
qw306
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-9-8
收藏
得分:0 
哦~~.. :( ~ 没看到..~~
谁会的能不能修改下..不要子菜单透明..
2007-02-06 17:38
快速回复:[求助]下拉菜单问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050018 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved