jQuery ui背景色动态渐变导航菜单

<!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>jQuery ui背景色动态渐变导航菜单_我爱模板 www.5imoban.net</title>
<!--引入开始-->
<style type="text/css">
#nav{position:relative; margin:40px; background:#eee; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:21px; -moz-border-radius:5px; -khtml-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; -moz-box-shadow:2px 2px 3px #ccc; -webkit-box-shadow:2px 2px 3px #ccc; box-shadow:2px 2px 3px #ccc;}
#nav .clear{clear:both;}
#nav ul{padding:0 0 0 5px; margin:0; list-style:none;}
#nav li{float:left; margin:5px 10px 5px 0; background:#eee; -moz-border-radius:5px; -khtml-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
#nav li a{text-decoration:none; color:#9e0039; display:block; padding:10px 15px;}
</style>
<script src="http://www.5imoban.net/download/jquery/jquery-1.6.min.js"></script>
<script src="http://www.5imoban.net/download/jquery/jQuery-UI-v1.9.2.min.js"></script>
<!-- IE 圆角 -->
<script src="http://www.5imoban.net/download/jquery/DD_roundies_0.0.2a-min.js"></script>
<script>
DD_roundies.addRule("#nav", "5px");
DD_roundies.addRule("#nav li", "5px");
</script>
<script>
$(document).ready(function(){
$nav_li=$("#nav li");
$nav_li_a=$("#nav li a");
var animSpeed=450; //背景色渐变时间,单位毫秒
var hoverTextColor="#fff"; //鼠标移上去的文字颜色
var hoverBackgroundColor="#9e0039"; //鼠标移上去的最终背景色
var textColor=$nav_li_a.css("color");
var backgroundColor=$nav_li.css("background-color");
//文字变色动画
$nav_li_a.hover(function() {
var $this=$(this);
$this.stop().animate({ color: hoverTextColor }, animSpeed);
},function() {
var $this=$(this);
$this.stop().animate({ color: textColor }, animSpeed);
});
//背景变色动画
$nav_li.hover(function() {
var $this=$(this);
$this.stop().animate({ backgroundColor: hoverBackgroundColor }, animSpeed);
},function() {
var $this=$(this);
$this.stop().animate({ backgroundColor: backgroundColor }, animSpeed);
});
});
</script>
<!--引入结束-->
<style>
body{margin:0; padding:0;}
ul#wimoban_nav{padding-left:50px; margin-bottom:10px; border-bottom:2px solid #ccc; overflow:hidden; _zoom:1;}
ul#wimoban_nav li{float:left; display:inline; margin:10px;}
ul#wimoban_nav li a{display:block; font-size:16px;}
ul#wimoban_nav li a,#wimoban_p,#wimoban_p a{color:#000; font-family:"微软雅黑";}
ul#wimoban_nav li a:hover,#wimoban_p a:hover{color:red;}
#wimoban_p{text-align:center; font-size:14px; clear:both;}
</style>
</head>
<body oncontextmenu='return false' ondragstart='return false'>
<ul >我爱模板网</a></p>
<p>*尊重他人劳动成果,转载请自觉注明出处!注:此代码仅供学习交流,请勿用于商业用途。</p>
<p></p>
</div>
</body>
</html>

 

 

使用方法

1、在head引入下面的代码:

01 <style type="text/css">
02 #nav{position:relative; margin:40px; background:#eee; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:21px; -moz-border-radius:5px; -khtml-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; -moz-box-shadow:2px 2px 3px #ccc; -webkit-box-shadow:2px 2px 3px #ccc; box-shadow:2px 2px 3px #ccc;}
03 #nav .clear{clear:both;}
04 #nav ul{padding:0 0 0 5px; margin:0; list-style:none;}
05 #nav li{float:left; margin:5px 10px 5px 0; background:#eee; -moz-border-radius:5px; -khtml-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
06 #nav li a{text-decoration:none; color:#9e0039; display:block; padding:10px 15px;}
07 </style>
11 <script>
12 DD_roundies.addRule("#nav""5px");
13 DD_roundies.addRule("#nav li""5px");
14 </script>
15 <script>
16 $(document).ready(function(){
17     $nav_li=$("#nav li");
18     $nav_li_a=$("#nav li a");
19     var animSpeed=450; //背景色渐变时间,单位毫秒
20     var hoverTextColor="#fff"//鼠标移上去的文字颜色
21     var hoverBackgroundColor="#9e0039"//鼠标移上去的最终背景色
22     var textColor=$nav_li_a.css("color");
23     var backgroundColor=$nav_li.css("background-color");
24     //文字变色动画
25     $nav_li_a.hover(function() {
26         var $this=$(this);
27         $this.stop().animate({ color: hoverTextColor }, animSpeed);
28     },function() {
29         var $this=$(this);
30         $this.stop().animate({ color: textColor }, animSpeed);
31     });
32     //背景变色动画
33     $nav_li.hover(function() {
34         var $this=$(this);
35         $this.stop().animate({ backgroundColor: hoverBackgroundColor }, animSpeed);
36     },function() {
37         var $this=$(this);
38         $this.stop().animate({ backgroundColor: backgroundColor }, animSpeed);
39     });
40 });
41 </script>

2、在您的导航区域引入下面的html代码:

01 <div id="nav">
02 <ul>
03     <li><a href="#about">About</a></li>
04         <li><a href="#portfolio">Portfolio</a></li>
05         <li><a href="#recent">Recent</a></li>
06         <li><a href="#experiments">Experiments</a></li>
07         <li><a href="#contact">Contact</a></li>
08     </ul>
09     <div class="clear"></div>
10 </div>