jQuery实战之仿Flash跳动的按钮效果

开发 前端
运用jQuery在配合漂亮的UI,就可以做出让用户赏心悦目的体验。

下面这个小例子,灵感来源于百度有啊的应用(现在好像没有了),就是当鼠标移上去和移除,图标会有缓动的效果。效果不比flash的差。

51CTO推荐专题:jQuery从入门到精通  jQuery给力插件大阅兵

下面是的效果图:图标很好设计,在这里就不教大家怎么设计了。

jQuery实战之仿Flash跳动的按钮效果

下面是JQ的代码部分:

  1. $(function(){   
  2.       //append img to LI   
  3.       $("#nav-shadow li").append('<img class="shadow" src="images/reflaction_pic.jpg" 
  4. width="60" height="32"  alt="" />');//这是阴影的图片   
  5.       //append hover event   
  6.       $("#nav-shadow li").hover(function(){   
  7.      //define e for tihs   
  8.           var $e = this;   
  9.          $($e).find("a").stop().animate({marginTop:'-14px'},250,function(){//回调函数控制   
  10.               $($e).find("a").animate({marginTop:'-10px'},250);  
  11.               
  12.          });  
  13.          $($e).find("img.shadow").stop().animate({width:"80%",opacity:"0.3",marginLeft:"8px"},250);                  
  14.            
  15.      },function(){  
  16.          var $e = this;  
  17.          $($e).find("a").stop().animate({marginTop:"4px"},250,function(){  
  18.              $($e).find("a").animate({marginTop:"0px"},250);  
  19.          });      
  20.          $($e).find("img.shadow").stop().animate({width:"100%",opacity:"1",marginLeft:"0px"},250);              
  21.         }  
  22.         )  
  23.      }) 

分析:

首先增加倒影:

  1. $("#nav-shadow li").append('<img class="shadow" src="images/reflaction_pic.jpg" 
  2. width="60" height="32"  alt="" />'

然后注册,hover事件,用回调函数控制弹回去时候的效果。阴影的距离感是通过透明度控制的。

下面是HTML代码:

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">   
  2.   <html>   
  3.      <head>   
  4.          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   
  5.          <title>button_effect</title>   
  6.          <script type="text/javascript" src="jquery-1.4.2.min.js"></script>   
  7.          <script type="text/javascript" src="action.js"></script>   
  8.          <style type="text/css">   
  9.              *{ margin:0; padding:0;}  
  10.              div{ width:500px; height:500px; margin:100px 0 auto;}  
  11.              ul,ol{ list-style:none; list-style-type:none;}  
  12.              a,a:visited,a:hover{ display:block; text-decoration:none; color:#ccc; text-indent:-9999px; 
  13. outline: 0 none; width:61px; height:60px; z-index:2; overflow:hidden;  position:relative;}  
  14.              li{ float:left; width:61px; height:92px; margin-left:10px; position:relative;}      
  15.              #nav-shadow li.chang-one a{ background:url(images/button_pic.jpg) no-repeat left top;}  
  16.              #nav-shadow li.chang-two a{background:url(images/button_pic.jpg) no-repeat -60px top;}  
  17.              #nav-shadow li.chang-three a{background:url(images/button_pic.jpg) no-repeat -120px top;}  
  18.              #nav-shadow li.chang-four a{background:url(images/button_pic.jpg) no-repeat -180px top;}  
  19.              #nav-shadow li.chang-five a{background:url(images/button_pic.jpg) no-repeat -240px top;}  
  20.              #nav-shadow li img.shadow{margin:0 auto; position:absolute; bottom:0px; left:0px; z-index:1;}  
  21.          </style>  
  22.      </head>  
  23.      <body>  
  24.       <div id="content">  
  25.           <ul id="nav-shadow">  
  26.               <li class="chang-one"><a href="#" title="reflaction_one">click me</a></li>  
  27.              <li class="chang-two"><a href="#" title="reflaction_two">click me</a></li>  
  28.              <li class="chang-three"><a href="#" title="reflaction_three">click me</a></li>  
  29.              <li class="chang-four"><a href="#" title="reflaction_four">click me</a></li>  
  30.              <li class="chang-five"><a href="#" title="reflaction_five">click me</a></li>          
  31.           </ul>  
  32.       </div>  
  33.      </body>  
  34.  </html> 

大家在用的时候,只需要设计出好看的图标就可以了。

新加了源码下载:下载

原文链接:http://www.cnblogs.com/blacksheep/archive/2011/04/13/2014416.html

【编辑推荐】

  1. 分享24款非常有用的jQuery插件
  2. jQuery拖动布局实现排序结果同步数据库
  3. 手把手教你用jQuery做动画插件
  4. ASP.NET MVC中很酷的jQuery验证插件
  5. 30个最新超棒的jQuery灯箱插件
责任编辑:陈贻新 来源: 博客园
相关推荐

2011-03-30 14:33:57

jQueryJavaScript

2010-09-02 09:26:04

FlashAndroid

2011-06-03 09:05:18

Android iphone tab

2011-06-03 09:34:14

Android iphone tab

2011-05-04 09:05:39

Flash

2015-07-21 15:22:20

点赞仿知乎按钮动画

2015-07-17 10:41:59

点赞按钮

2015-03-30 14:24:06

网易布局

2015-02-02 16:42:49

特效密码锁

2012-05-29 10:36:43

jQuery

2012-06-19 13:45:57

Web

2015-07-23 15:15:06

动态弹出

2015-01-19 12:19:04

iOS源码ActionSheet仿QQ音乐

2012-04-26 10:56:05

jQuery效果

2016-08-30 21:36:56

JavascriptCSSWeb

2017-03-22 10:35:06

AndroidRecyclerVie滑动效果

2015-03-31 18:19:37

饿了么动画效果

2009-09-07 06:56:46

C#透明窗体

2011-07-21 16:10:11

button按钮jQuery Mobi

2009-12-29 14:26:04

WPF按钮
点赞
收藏

51CTO技术栈公众号