jQuery实战之仿Flash跳动的按钮效果
创始人
2024-07-26 01:00:38
0

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

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

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

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

下面是JQ的代码部分:

  1. $(function(){   
  2.       //append img to LI   
  3.       $("#nav-shadow li").append('
  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('
  2. width="60" height="32"  alt="" />') 

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

下面是HTML代码:

  1.    
  2.      
  3.         
  4.             
  5.          button_effect   
  6.             
  7.             
  8.             
  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.            
  22.        
  23.        
  24.         
  25.             
  26.               click me
  27.  
  28.              click me
  29.  
  30.              click me
  31.  
  32.              click me
  33.  
  34.              click me
  35.           
  36.             
  37.       
 
  •        
  •   
  • 大家在用的时候,只需要设计出好看的图标就可以了。

    新加了源码下载:下载

    原文链接: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灯箱插件

    相关内容

    热门资讯

    如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
    如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
    施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
    20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
    德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
    为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
    《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
    2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...