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;
}
HTML代码
Javascript代码
/*
menu for javascript
author:mr·zhong
date:2010-01-25
*/
/*Determine whether the current submenu is displayed or hidden* /
var MenuShowOrHide = false;
$(function(){
SetMenuID();
BindMenuHoverEval();
BindChideMenuHoverEval();
});
/*
Set the main and submenu button IDs
*/
function SetMenuID(){
var id = 1;
$('#ul_menu a').each(function(){
$(this).attr("id","a_" id);
var chideObj = $(this).next();
chideObj.attr("id","ChideMenu_a_" id) ;
chideObj.hide();
id ;
});
}
/*
Set menu color style
*/
function SetMenuColor(menuID, isSelected){
if(isSelected) $("#" menuID).addClass("menuSelected");
else $("#" menuID).removeClass("menuSelected");
}
/*
Set the submenu to show or hide
*/
function ShowOrHideChideMenu(menuID,isShow){
var obj = $("#" menuID);
if(isShow)
{
obj.slideDown("slow");
}
else obj.hide("slow");
}
/*
Bind the main menu mouse event
*/
function BindMenuHoverEval(){
$("#ul_menu a").each(function(){
$(this).hover(function(){
ShowOrHideChideMenu( "ChideMenu_" $(this).attr("id"),true);
MenuShowOrHide = true;
},function(){
setTimeout('Hide(ChideMenu_' $(this).attr ("id") ')',500);
});
});
}
/*
Bind submenu mouse events
*/
function BindChideMenuHoverEval(){
$("#ul_menu .chideMenuForShow").each(function(){
$(this).hover(function(){
MenuShowOrHide = true;
}, function(){
MenuShowOrHide = false;
Hide($(this).attr("id"));
});
});
}
/*
Hide submenu
*/
function Hide(id){
if(!MenuShowOrHide) ShowOrHideChideMenu(id,false);
}
Download address :
http://www.jb51.net/jiaoben/24160.html