简单菜单

 <html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 <title>简单菜单</title>
 
 <!--
 提供定位函数,用iframe作载体,不会被select挡住
 -->
 <style>  
  #div1 {
   position:absolute;
   z-index:1;
   width:100px;
   height:130px;
   background-color:#d2e8ff;
   visibility:hidden;
  }
  
  .sub {
   cursor:hand;
   font-size:12px;
  }
  
  a {
   cursor:hand;
   text-decoration:none;
   color:blue;
   font-size:12px;
   margin-left:50px;
   height:10px;
  }
  
  select {
   width:200px;
   margin-top:10px;
  }
 </style>
 
 <script>
  function show(){
   var div1 = document.getElementById("div1");
   div1.style.top = getTop(div1.parentNode) + div1.parentNode.clientHeight + "px";
   div1.style.left = getLeft(div1.parentNode);
   div1.style.visibility = 'visible';
   //创建一个无内容的iframe来挡住select框
   var menuShim = document.getElementById(div1.id + "_shim");
   if (menuShim) {
    menuShim.style.display = "block";
   } else {
    menuShim = document.createElement("iframe");
    menuShim.id = div1.id + "_shim";
    menuShim.frameBorder = "no";
    menuShim.scrolling = "no";
    menuShim.width = div1.clientWidth;
    menuShim.height = div1.clientHeight;
    menuShim.style.position = "absolute";
    menuShim.style.left = getLeft(div1);
    menuShim.style.top = getTop(div1);
    document.body.appendChild(menuShim);
   }
  }
  
  function hide(){
   var curObj = document.getElementById("div1");
   curObj.style.visibility='hidden'
   var menuShim = document.getElementById(curObj.id + "_shim");
   if (menuShim !== null) {
    menuShim.style.display = "none";
   }
  }
  
  function getLeft(obj) {
   var thisValue = 0;
   if (obj) {
    thisValue = obj.offsetLeft + getLeft(obj.offsetParent);
   }
   return thisValue;
  }
  
  function getTop(obj) {
   var thisValue = 0;
   if (obj) {
    thisValue = obj.offsetTop + getTop(obj.offsetParent);
   }
   return thisValue;
  }
 
 </script>
</head>
<body>
 <a id="menu" οnmοuseοver="show()" οnmοuseοut="hide()">Menu Test
  <div id="div1">
   <div class="sub" οnmοuseοver="style.backgroundColor='highlight'" οnmοuseοut="style.backgroundColor=''">sub menu 1</div>
   <div class="sub" οnmοuseοver="style.backgroundColor='highlight'" οnmοuseοut="style.backgroundColor=''">sub menu 2</div>
  </div>
 </a>
 
 <br>
 
 <select><option>aa</option><option>bb</option></select>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值