CSS样式
body
{
font-size:12px;
}
.menuBox
{
width:50%;
height:auto;
margin:0 auto;
}
.menuBox ul
{
margin:0px;
padding:0px;
}
.menuBox ul li
{
float:left;
display:block;
width:18%;
height:30px;
line-height:25px;
list-style:none;
margin-right:1px;
}
.menuBox ul li a
{
display:block;
width:100%;
height:100%;
background-color:Black;
color:White;
text-decoration:none;
text-align:center;
}
.menuBox ul li a:hover
{
display:block;
width:100%;
height:100%;
background-color:Silver;
color:Red;
text-decoration:none;
}
.menuSelected
{
display:block;
width:100%;
height:100%;
background-color:Silver;
color:Red;
text-decoration:none;
}
.chideMenuForShow
{
width:200px;
position:absolute;
height:auto;
border:1px solid #ccc;
float:right;
background-color:Silver;
}
{
font-size:12px;
}
.menuBox
{
width:50%;
height:auto;
margin:0 auto;
}
.menuBox ul
{
margin:0px;
padding:0px;
}
.menuBox ul li
{
float:left;
display:block;
width:18%;
height:30px;
line-height:25px;
list-style:none;
margin-right:1px;
}
.menuBox ul li a
{
display:block;
width:100%;
height:100%;
background-color:Black;
color:White;
text-decoration:none;
text-align:center;
}
.menuBox ul li a:hover
{
display:block;
width:100%;
height:100%;
background-color:Silver;
color:Red;
text-decoration:none;
}
.menuSelected
{
display:block;
width:100%;
height:100%;
background-color:Silver;
color:Red;
text-decoration:none;
}
.chideMenuForShow
{
width:200px;
position:absolute;
height:auto;
border:1px solid #ccc;
float:right;
background-color:Silver;
}
HTML代码
<div class&#61;&#39;menuBox&#39;>
<ul id&#61;&#39;ul_menu&#39;>
<li>
<a href&#61;&#39;#&#39;>menu1a>
<div class&#61;"chideMenuForShow">
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu2a>
<div class&#61;"chideMenuForShow">
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu3a>
<div class&#61;"chideMenuForShow">
<div>menu3div>
<div>menu3div>
<div>menu3div>
<div>menu3div>
<div>menu3div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu4a>
<div class&#61;"chideMenuForShow">
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu5a>
<div class&#61;"chideMenuForShow">
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
div>
li>
ul>
div>
<ul id&#61;&#39;ul_menu&#39;>
<li>
<a href&#61;&#39;#&#39;>menu1a>
<div class&#61;"chideMenuForShow">
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
<div>menu1div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu2a>
<div class&#61;"chideMenuForShow">
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
<div>menu2div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu3a>
<div class&#61;"chideMenuForShow">
<div>menu3div>
<div>menu3div>
<div>menu3div>
<div>menu3div>
<div>menu3div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu4a>
<div class&#61;"chideMenuForShow">
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
<div>menu4div>
div>
li>
<li>
<a href&#61;&#39;#&#39;>menu5a>
<div class&#61;"chideMenuForShow">
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
<div>menu5div>
div>
li>
ul>
div>
JS代码
/*
menu for Javascript
author:mr·zhong
date:2010-01-25
*/
/*判断当前子菜单显示或隐藏*/
var MenuShowOrHide &#61; false;
$(function(){
SetMenuID();
BindMenuHoverEval();
BindChideMenuHoverEval();
});
/*
设置主、子菜单按钮ID
*/
function SetMenuID(){
var id &#61; 1;
$(&#39;#ul_menu a&#39;).each(function(){
$(this).attr("id","a_" &#43; id);
var chideObj &#61; $(this).next();
chideObj.attr("id","ChideMenu_a_" &#43; id);
chideObj.hide();
id&#43;&#43;;
});
}
/*
设置菜单颜色样式
*/
function SetMenuColor(menuID,isSelected){
if(isSelected) $("#" &#43; menuID).addClass("menuSelected");
else $("#" &#43; menuID).removeClass("menuSelected");
}
/*
设置子菜单显示或隐藏
*/
function ShowOrHideChideMenu(menuID,isShow){
var obj &#61; $("#" &#43; menuID);
if(isShow)
{
obj.slideDown("slow");
}
else obj.hide("slow");
}
/*
绑定主菜单鼠标事件
*/
function BindMenuHoverEval(){
$("#ul_menu a").each(function(){
$(this).hover(function(){
ShowOrHideChideMenu("ChideMenu_" &#43; $(this).attr("id"),true);
MenuShowOrHide &#61; true;
},function(){
MenuShowOrHide &#61; false;
setTimeout(&#39;Hide("ChideMenu_&#39; &#43; $(this).attr("id") &#43;&#39;")&#39;,500);
});
});
}
/*
绑定子菜单鼠标事件
*/
function BindChideMenuHoverEval(){
$("#ul_menu .chideMenuForShow").each(function(){
$(this).hover(function(){
MenuShowOrHide &#61; true;
},function(){
MenuShowOrHide &#61; false;
Hide($(this).attr("id"));
});
});
}
/*
隐藏子菜单
*/
function Hide(id){
if(!MenuShowOrHide) ShowOrHideChideMenu(id,false);
}
menu for Javascript
author:mr·zhong
date:2010-01-25
*/
/*判断当前子菜单显示或隐藏*/
var MenuShowOrHide &#61; false;
$(function(){
SetMenuID();
BindMenuHoverEval();
BindChideMenuHoverEval();
});
/*
设置主、子菜单按钮ID
*/
function SetMenuID(){
var id &#61; 1;
$(&#39;#ul_menu a&#39;).each(function(){
$(this).attr("id","a_" &#43; id);
var chideObj &#61; $(this).next();
chideObj.attr("id","ChideMenu_a_" &#43; id);
chideObj.hide();
id&#43;&#43;;
});
}
/*
设置菜单颜色样式
*/
function SetMenuColor(menuID,isSelected){
if(isSelected) $("#" &#43; menuID).addClass("menuSelected");
else $("#" &#43; menuID).removeClass("menuSelected");
}
/*
设置子菜单显示或隐藏
*/
function ShowOrHideChideMenu(menuID,isShow){
var obj &#61; $("#" &#43; menuID);
if(isShow)
{
obj.slideDown("slow");
}
else obj.hide("slow");
}
/*
绑定主菜单鼠标事件
*/
function BindMenuHoverEval(){
$("#ul_menu a").each(function(){
$(this).hover(function(){
ShowOrHideChideMenu("ChideMenu_" &#43; $(this).attr("id"),true);
MenuShowOrHide &#61; true;
},function(){
MenuShowOrHide &#61; false;
setTimeout(&#39;Hide("ChideMenu_&#39; &#43; $(this).attr("id") &#43;&#39;")&#39;,500);
});
});
}
/*
绑定子菜单鼠标事件
*/
function BindChideMenuHoverEval(){
$("#ul_menu .chideMenuForShow").each(function(){
$(this).hover(function(){
MenuShowOrHide &#61; true;
},function(){
MenuShowOrHide &#61; false;
Hide($(this).attr("id"));
});
});
}
/*
隐藏子菜单
*/
function Hide(id){
if(!MenuShowOrHide) ShowOrHideChideMenu(id,false);
}
Demo 下载地址 http://files.cnblogs.com/keke/菜单.rar