js实现菜单栏上下旋转动画效果

原始图片:
当鼠标放到”首页”上时:
< div  id ="menu2"  class ="menu">
                     < ul >
                         < li ><  a  href  ="index.aspx">  首  页 </ a  ></ li >
                         < li ><  a  href  ="news.aspx">  实时资讯 </ a  ></ li >
                     </ ul >
             </ div >    

      < script  src ="js/jquery-1.7.2.min.js"  type  ="text/javascript"></  script >
       < script  type ="text/javascript"  language  ="javascript">
           var  $jq = jQuery.noConflict();
          $jq(
        $jq(document).ready(  function () {

             /*  1st example     */

             /// wrap inner content of each anchor with first layer and append background layer
            $jq(  "#menu1 li a" ).wrapInner( '<span class="out"></span>'  ).append( '<span class="bg"></span>' );

             // loop each anchor and add copy of text content
            $jq(  "#menu1 li a" ).each( function  () {
                $jq(  '<span class="over">'  + $jq( this ).text() +  '</span>' ).appendTo( this  );
            });

            $jq(  "#menu1 li a" ).hover( function  () {
                 // this function is fired when the mouse is moved over
                $jq(  ".out" ,  this  ).stop().animate({  'top' :  '40px'  }, 250);  // move down - hide
                $jq(  ".over" ,  this  ).stop().animate({  'top' :  '0px'  }, 250);  // move down - show
                $jq(  ".bg" ,  this  ).stop().animate({  'top' :  '0px'  }, 120);  // move down - show

            },  function () {
                 // this function is fired when the mouse is moved off
                $jq(  ".out" ,  this  ).stop().animate({  'top' :  '0px'  }, 250);  // move up - show
                $jq(  ".over" ,  this  ).stop().animate({  'top' :  '-40px'  }, 250);  // move up - hide
                $jq(  ".bg" ,  this  ).stop().animate({  'top' :  '-40px'  }, 120);  // move up - hide
            });


             /*  2nd example     */

            $jq(  "#menu2 li a" ).wrapInner( '<span class="out"></span>'  );

            $jq(  "#menu2 li a" ).each( function  () {
                 try  {
                     var  urlName = window.location.pathname  // 获取当前  URL
                     var  param = urlName.split( "/"  )[1];
                     if  ($jq( this  ).attr( "href" ) == param) {
                        $jq(  this ).attr( "class"  ,  "over" );
                    }
                    $jq(  '<span class="over">'  + $jq( this ).text() +  '</span>' ).appendTo( this  );
                }
                 catch  (e) {
                }
                 finally  {
              }
            });

            $jq(  "#menu2 li a" ).hover( function  () {
                $jq(  ".out" ,  this  ).stop().animate({  'top' :  '40px'  }, 300);  // move down - hide
                $jq(  ".over" ,  this  ).stop().animate({  'top' :  '0px'  }, 300);  // move down - show

            },  function () {
                $jq(  ".out" ,  this  ).stop().animate({  'top' :  '0px'  }, 300);  // move up - show
                $jq(  ".over" ,  this  ).stop().animate({  'top' :  '-40px'  }, 300);  // move up - hide
            });

        })
)
      </ script >  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值