特效介绍
jQuery ui背景色动态渐变导航菜单,导航栏hover的时候,背景色会从白色渐变到红色。完美兼容IE6。DD_roundies_0.0.2a-min.js是IE圆角插件。运行下面代码查看导航效果:
提示:您可以先修改部分代码再运行
使用方法
1、在head引入下面的代码:
<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> <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>2、在您的导航区域引入下面的html代码:
<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>