当前位置:编程学习 > JS >>

一个简洁型伸缩菜单

一个简洁型伸缩菜单,黑色超酷风格,简约实用,喜欢简洁的朋友可以试用一下哦。
答案:<!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=utf-8" />
<title>一个简洁型伸缩菜单</title>
<style type="text/css">
*{margin:0; padding:0;}
body{ font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#666;}
#box{width:200px; border:1px solid #ccc;}
.title{ font-size:12px; padding-left:3px; height:20px; border-bottom:1px solid #fff; background:#000; line-height:20px; color:#FFF; cursor:pointer;}
.content{ padding:5px; height:150px;}
</style>
<script type="text/javascript">
function flexMenu(id)
{
 var $id = document.getElementById(id);
 var titleList = $id.getElementsByTagName('h2');
 var contentList = $id.getElementsByTagName('div');
 titleList[titleList.length-1].style.border = 'none';
 for(var i=0;i<titleList.length;i++)
 {   
  titleList[i].onclick = function()
  {
   for(var a=0;a<contentList.length;a++)
   {
    contentList[a].style.display = 'none';
   }
   if(this.nextSibling.nodeType=='3')
   {
    this.nextSibling.nextSibling.style.display = '';
   }else
   {
    this.nextSibling.style.display = '';
   }
  }
 }
}
window.onload = function(){ flexMenu('box')}
</script>
</head>
<body>
<div id="box">
 <h2 class="title">网站总导航</h2> 
    <div class="content" ><a href="#"> 网站首页</a></div>
    <h2 class="title">网页特效</h2>
    <div class="content" style="display:none;"><a href="/jscss/">网页特效</a></div>
    <h2 class="title">源代码下载</h2>
    <div class="content" style="display:none;"><a href="#">电子教程</a></div>
</div>
</body>
</html>

上一个:JS+CSS多个滑动门重复调用封闭类
下一个:Discuz论坛的阴影二级下滑菜单

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,