以下是 jQuery仿flash导航代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!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=gb2312" />
<meta name="keywords" content="JS代码,{keyword},JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为{title},属于站长常用代码" />
<title>{title}</title>
<link href="css/flipmenu.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/flipmenu-min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var menu1 = new Flipmenu("flip_menu1");
var menu2 = new Flipmenu("flip_menu2");
});
</script>
<style type="text/css">
h1 {
font-family: arial;
font-size: 14pt;
color: #318DF2;
margin-top: 35px;
}
#wrap {
margin : 0px auto;
width : 200px;
}
</style>
</head>
<body>
<!-- 代码 开始 -->
<div id="wrap">
<h1>jQuery仿flash导航代码</h1>
<div id="flip_menu1">
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
<a href="#">one two </a>
</div>
</div>
</body>
</html>
JS代码(flipmenu-min.js):
var Flipmenu=function(container){
this.initialize=function(){
this.container=$("#"+container);
if(!this.container){
alert("Could not locate \""+container+"\"");
return;
}
this.container.addClass("flipmenu");
this.readLinks();
}
this.readLinks=function(){
var self=this;
this.container.find("a").each(function(i,el){
self.render(i,el);
}
);
}
this.render=function(inx,link){
$(link).wrap("<div class=\"flipmenu_box\"></div>");
$(link).addClass(($(link).hasClass("active"))?"flipmenu_link_active":"flipmenu_link");
var parent=$(link).parent()parent.css({
width:(link.offsetWidth)+"px",height:link.offsetHeight+"px"}
);
var clone=$(link).clone();
clone.removeClass("flipmenu_link");
clone.addClass("flipmenu_link_over").css({
top:link.offsetHeight+"px",left:"0px"}
);
parent.append(clone);
$(parent).bind("mouseenter",this,this.onMouseEnter);
$(parent).bind("mouseleave",this,this.onMouseLeave);
}
this.onMouseEnter=function(event){
var first=$(this.firstChild);
if(first.hasClass("active"))return;
var second=first.next();
first.animate({
top:"-"+first.outerHeight()}
,250);
second.animate({
top:"0"}
,250);
}
this.onMouseLeave=function(event){
var first=$(this.firstChild);
if(first.hasClass("active"))return;
var second=first.next();
first.stop().animate({
top:"0"}
,250);
second.stop().animate({
top:$(this).outerHeight()}
,250);
}
this.initialize();
}
CSS代码(flipmenu.css):
.flipmenu{font-family:Arial,Helvetica,sans-serif;font-size:16pt;font-weight:bold;position:relative;background:url(../images/bg.png);padding:15px;}
.flipmenu_box{overflow:hidden;position:relative;padding:0px;margin:0px;}
.flipmenu_link,.flipmenu_link_over,.flipmenu_link_active{text-decoration:none;text-transform:uppercase;color:#FFF;cursor:pointer;white-space:pre;position:absolute;}
.flipmenu_link{top:0px;left:0px;}
.flipmenu_link_over,.flipmenu_link_active{color:#B7DF63;}