<!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 id="wimoban_nav">
<li><a title="返回网站首页" href="http://www.5imoban.net/">首页</a></li>
<li><a title="网页PSD模板下载" href="http://www.5imoban.net/psdmoban/">PSD模板</a></li>
<li><a title="网页CSS模板下载" href="http://www.5imoban.net/cssmoban/">CSS模板</a></li>
<li><a title="网页特效、网页插件" href="http://www.5imoban.net/texiao/">特效插件</a></li>
<li><a title="整站源码下载" href="http://www.5imoban.net/yuanma/">源码下载</a></li>
<li><a title="酷站欣赏" href="http://www.5imoban.net/kuzhan/">酷站欣赏</a></li>
<li><a title="建站资源" href="http://www.5imoban.net/ziyuan/">建站资源</a></li>
<li><a title="建站视频教程、建站教程" href="http://www.5imoban.net/jiaocheng/">建站教程</a></li>
<li><a title="建站心得、互联网事、心境之旅" href="http://www.5imoban.net/article/">心境之旅</a></li>
</ul>
<!-- 代码开始 -->
<div id="nav">
<ul>
<li><a href="#about">About</a></li>
<li><a href="#portfolio">Portfolio</a></li>
<li><a href="#recent">Recent</a></li>
<li><a href="#experiments">Experiments</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div class="clear"></div>
</div>
<!-- 代码结束 -->
<div id="wimoban_p">
<p>来代码整理:<a href="http://www.5imoban.net/" title="模板网" alt="模板网">我爱模板网</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;} |
12 |
DD_roundies.addRule( "#nav" , "5px" );
|
13 |
DD_roundies.addRule( "#nav li" , "5px" );
|
16 |
$(document).ready( function (){
|
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" );
|
25 |
$nav_li_a.hover( function () {
|
27 |
$ this .stop().animate({ color: hoverTextColor }, animSpeed);
|
30 |
$ this .stop().animate({ color: textColor }, animSpeed);
|
33 |
$nav_li.hover( function () {
|
35 |
$ this .stop().animate({ backgroundColor: hoverBackgroundColor }, animSpeed);
|
38 |
$ this .stop().animate({ backgroundColor: backgroundColor }, animSpeed);
|
2、在您的导航区域引入下面的html代码:
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 >
|
09 |
< div class = "clear" ></ div >
|