移动端导航条下划线或者背景色平移效果或者拉伸效果实现

2020-08-06  本文已影响0人  焚心123
2.png
  nav {
        position: relative;
        .vw(height,88);
        width:100%;
        background: #fff;
        .vw(font-size,30);
      }
      nav .line {
        .vw(height,66);
        .vw(width,500);
        position: absolute;
        // bottom: 0;
        .vw(bottom,10);
        background: #FFF2F3;
        .vw(border-radius,40);
        opacity: .4;
        z-index: 111;
      }
    //   nav ul li .active{
    //     color:#F9404A ;
    //   }
      nav ul {
          width: 100%;
          height: 100%;
        display: flex;
        align-items: center;
        justify-content: space-around;
      }
      nav ul li {
          text-align: center;
          width: 40%;
        // height: 30px;
        // .vw(margin-right,40);
        transition: all 0.4s;
        color:#9B9B9B ;
        // color:#F9404A ;
      }
      nav ul li  {
        color:#9B9B9B ;
      }
      nav ul li.active{
        color:#F9404A !important;
        font-weight: bold;
      }
   <nav>
            <ul>
                <li class="active" @click="toggle(0)" v-if="isIpone">
                    交易记录
                </li>
                <li class="active" @click="toggle(1)" v-if="!isIpone">
                    可兑换签纸贺
                </li>
                <li @click="toggle(2)">
                    兑换历史
                </li>
            </ul>
            <div class="line"></div>
        </nav>
 // 头部选项卡的步骤

        var nav = $('nav');
        var line = $('.line');

        var active = nav.find('.active');
        var pos = 0;
        var wid = 0;
        if (active.length) {
            pos = active.position().left;
            wid = active.width();
            line.css({
                left: pos,
                width: wid
            });
        }

        nav.find('ul li').click(function (e) {

            if (!$(this).hasClass('active')) {
                var _this = $(this);
                nav.find('ul li').removeClass('active');
                var position = _this.position();
                var width = _this.width();
                if (position.left >= pos) {
                    // line.animate({ left: position.left - pos }
                    // ,100,function(){
                    //     line.animate({width:width},100)
                    // })
                    line.animate({
                        width: ((position.left - pos) + width)
                    }, 100, function () {

                        line.animate({
                            width: width,
                            left: position.left
                        }, 150);
                        _this.addClass('active');

                    });
                } else {

                    line.animate({
                        left: position.left,
                        // width: ((pos - position.left) + wid)
                    }, 300, function () {
                        line.animate({
                            width: width
                        }, 150);
                        _this.addClass('active');
                    });
                }

                pos = position.left;
                wid = width;
            }
        });
上一篇下一篇

猜你喜欢

热点阅读