热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

JS·经典·炫彩菜单(动画效果)forjquery

CSS样式body{font-size:12px;}.menuBox{width:50%;height:auto;margin:0auto;}.menuBoxul{margin:0

 

ContractedBlock.gifExpandedBlockStart.gifCSS样式

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;

}

 

ContractedBlock.gifExpandedBlockStart.gifHTML代码

<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>

 

 

ContractedBlock.gifExpandedBlockStart.gifJS代码

/*
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

转:https://www.cnblogs.com/keke/archive/2010/01/25/1655833.html



推荐阅读
author-avatar
_我的最愛
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有