搜索附件  
自丢网 附件中心 模板下载 网页特效 菜单导航代码 jQuery CSS3导航菜单下划线动画特效.zip

热门下载

左侧广告
版权所有:自丢网
For 2020-2050 © zidiu.com

jQuery CSS3导航菜单下划线动画特效.zip

 

jQuery CSS3导航菜单下划线动画特效:


一款简单漂亮的jQuery CSS3导航菜单下划线动画特效,鼠标点击导航菜单文字链接时,下划线线性流动动画效果。

  1. js代码

  2. <script>
  3. var nav = $('nav');
  4. var line = $('<div />').addClass('line');

  5. line.appendTo(nav);

  6. var active = nav.find('.active');
  7. var pos = 0;
  8. var wid = 0;

  9. if(active.length) {
  10.   pos = active.position().left;
  11.   wid = active.width();
  12.   line.css({
  13.     left: pos,
  14.     width: wid
  15.   });
  16. }

  17. nav.find('ul li a').click(function(e) {
  18.   if(!$(this).parent().hasClass('active')) {
  19.     e.preventDefault();

  20.     var _this = $(this);

  21.     nav.find('ul li').removeClass('active');

  22.     var position = _this.parent().position();
  23.     var width = _this.parent().width();

  24.     if(position.left >= pos) {
  25.       line.animate({
  26.         width: ((position.left - pos) + width)
  27.       }, 300, function() {
  28.         line.animate({
  29.           width: width,
  30.           left: position.left
  31.         }, 150);
  32.         _this.parent().addClass('active');
  33.       });
  34.     } else {
  35.       line.animate({
  36.         left: position.left,
  37.         width: ((pos - position.left) + wid)
  38.       }, 300, function() {
  39.         line.animate({
  40.           width: width
  41.         }, 150);
  42.         _this.parent().addClass('active');
  43.       });
  44.     }

  45.     pos = position.left;
  46.     wid = width;
  47.   }
  48. });
  49. </script>
复制代码