今天帮美工写个很简单的javascript菜单效果,在ie6, firefox下测试通过,整理了下代码,贴出来。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>menu</title>
<style type="text/css">
<!--
/*有部分CSS对菜单是不需要的,可以去掉*/
body {
 font-size: 12px;
 margin: 0px;
 padding: 0px;
}
form {
 font-size: 12px;
 margin: 0px;
 padding: 0px;
}
table,tr,td,div {
 font-size: 12px;
 line-height: 22px;
}
.text_white12 {
 font-size: 12px;
 color:#fff;
 line-height: 22px;
}
a:link {
 font-size: 12px;
 line-height: 25px;
 color: #000000;
 text-decoration: underline;
}
a:visited {
 font-size: 12px;
 line-height: 25px;
 color: #000000;
 text-decoration: underline;
}
a:hover {
 font-size: 12px;
 line-height: 25px;
 color: #ff0000;
 text-decoration: none;
}
a:actice {
 font-size: 12px;
 line-height: 25px;
 color: #000000;
 text-decoration: underline;
}
a.menu:link {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 font-weight:bold;
 text-decoration: none;
}
a.menu:visited {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 font-weight:bold;
 text-decoration: none;
}
a.menu:hover {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 font-weight:bold;
 text-decoration: underline;
}
a.menu:actice {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 font-weight:bold;
 text-decoration: none;
}
a.white_link:link {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 text-decoration: none;
}
a.white_link:visited {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 text-decoration: none;
}
a.white_link:hover {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 text-decoration: underline;
}
a.white_link:actice {
 font-size: 12px;
 line-height: 25px;
 color: #fff;
 text-decoration: none;
}

.title {
 font-size: 14px;
 font-weight: bold;
 color: #FF0000;
}
.green_title {
 font-size: 12px;
 font-weight: bold;
 color: #009900;
}

/*下面是各菜单的CSS,都差不多,也可以用一个,但有时可能菜单长度不一样*/
#layer_01 {
 position:absolute;
 width:175px;
 height:151px;
 z-index:1;
 visibility:hidden;
 border:1px dotted #CCCCCC;
}
#layer_02 {
 position:absolute;
 width:100px;
 height:120px;
 z-index:1;
 visibility:hidden;
 border:1px dotted #CCCCCC;
}
#layer_03 {
 position:absolute;
 width:100px;
 height:120px;
 z-index:1;
 visibility:hidden;
 border:1px dotted #CCCCCC;
}
#layer_04 {
 position:absolute;
 width:100px;
 height:120px;
 z-index:1;
 visibility:hidden;
 border:1px dotted #CCCCCC;
}
#layer_05 {
 position:absolute;
 width:100px;
 height:120px;
 z-index:1;
 visibility:hidden;
 border:1px dotted #CCCCCC;
}
-->
</style>
</head>
<script language="javascript">
/*核心的菜单代码*/
//取得元素绝对位置
function getAbsPoint(e) {
 var x = e.offsetLeft;
 var y = e.offsetTop;
 while (e = e.offsetParent) {
  x += e.offsetLeft;
  y += e.offsetTop;
 }
 return {"x":x, "y":y};
}
function over(o, menuName, offset) {
 if (offset == null) {
  offset = 2;
 }
 var menu = document.getElementById(menuName);
 var xy = getAbsPoint(o);
 menu.style.left = xy.x + "px";
 menu.style.top = (xy.y + o.offsetHeight + offset) + "px";
 clickDocument();
 menu.style.filter = "Alpha(Opacity=80)";
 menu.style.visibility = "visible";
 o.style.backgroundColor = "#00173A";
}
function out(o) {
 //o.style.backgroundColor = "#FFFFFF";
}
function clickDocument() {
 var divs = document.getElementsByTagName("div");
 for (var i = 0; i < divs.length; i++) {
  if (divs[i].getAttribute("ismenu") == "true") {
   divs[i].style.visibility = "hidden";
  }
 }
 var tds = document.getElementById("tbl_menu").getElementsByTagName("td");
 for (var i = 0; i < tds.length; i++) {
  tds[i].style.backgroundColor = "#00173A";
 }
}
document.onclick = clickDocument;
</script>
<body>
<script language="javascript">
//改动的页比较多,美工将其放入一个js里,这里整理到一个页面里
document.writeln("<div id=/"layer_01/" ismenu=/"true/">");
document.writeln("  <table width=/"120/" border=/"0/" cellpadding=/"1/" cellspacing=/"1/" bgcolor=/"#ffffff/">");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list01.html/">展会概况<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list02.html/">展会动态与活动<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list07.html/">参展商名录<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list08.html/">上届展会回顾<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list03.html/">主办与合作主办机构<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list04.html/">组团参展机构<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list05.html/">展馆简介<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list09.html/">重要通知<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Info_list06.html/">联系我们<//a><//td>");
document.writeln("    <//tr>");
document.writeln("  <//table>");
document.writeln("<//div>");
document.writeln("<div id=/"layer_02/" ismenu=/"true/">");
document.writeln("  <table width=/"120/" border=/"0/" cellpadding=/"1/" cellspacing=/"1/" bgcolor=/"#ffffff/">");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Join_list01.html/">展位费标准<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Join_list02.html/">参展申请表格<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Join_list03.html/">宣传推广<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Join_list04.html/">须知及注意事项<//a><//td>");
document.writeln("    <//tr>");
document.writeln("  <//table>");
document.writeln("<//div>");
document.writeln("<div id=/"layer_03/" ismenu=/"true/">");
document.writeln("  <table width=/"120/" border=/"0/" cellpadding=/"1/" cellspacing=/"1/" bgcolor=/"#ffffff/">");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Enregister.html/">网上预约登记表<//a><//td>");
document.writeln("    <//tr>");
document.writeln("  <//table>");
document.writeln("<//div>");
document.writeln("<div id=/"layer_04/" ismenu=/"true/">");
document.writeln("  <table width=/"120/" border=/"0/" cellpadding=/"1/" cellspacing=/"1/" bgcolor=/"#ffffff/">");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list01.html/">展品运输<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list02.html/">展台搭建商<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list04.html/">地接服务及展后考察<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list05.html/">酒店情况<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list06.html/">航班情况<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Service_list03.html/">会 刊<//a><//td>");
document.writeln("    <//tr>");
document.writeln("  <//table>");
document.writeln("<//div>");
document.writeln("<div id=/"layer_05/" ismenu=/"true/">");
document.writeln("  <table width=/"120/" border=/"0/" cellpadding=/"1/" cellspacing=/"1/" bgcolor=/"#ffffff/">");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Country.html/">国家概况<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Country_list02.html/">行业概况<//a><//td>");
document.writeln("    <//tr>");
document.writeln("    <tr>");
document.writeln("      <td>&nbsp;<a href=/"Country_list03.html/">法律法规<//a><//td>");
document.writeln("    <//tr>");
document.writeln("  <//table>");
document.writeln("<//div>");
</script>
<table width="700" border="0" cellpadding="0" cellspacing="0" bgcolor="#00173a" id="tbl_menu">
  <tbody>
    <tr>
      <td><a class="menu"
            href="Index.html">网站首页</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td οnmοuseοver="over(this, 'layer_01');" οnmοuseοut="out(this);"><a class="menu" href="Info.html">展会资讯</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td οnmοuseοver="over(this, 'layer_02');" οnmοuseοut="out(this);"><a class="menu" href="Join.html">参展与报名</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td οnmοuseοver="over(this, 'layer_03');" οnmοuseοut="out(this);"><a class="menu" href="Enregister.html">专业观众与登记</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td οnmοuseοver="over(this, 'layer_04');" οnmοuseοut="out(this);"><a class="menu" href="Service.html">展会服务</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td οnmοuseοver="over(this, 'layer_05');" οnmοuseοut="out(this);"><a class="menu" href="country.html">国别市场</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td><a class="menu" href="http://www.smetrade.org.cn/">返回主站</a></td>
      <td>&nbsp;&nbsp;|&nbsp;&nbsp;</td>
      <td><a class="menu" href="Index.html#">English</a></td>
    </tr>
  </tbody>
</table>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值