• jQuery实现导航条楼层跳转功能


    nav导航的html结构

            <!-- 导航 -->
            <!-- .part -->
         在需要跳转的楼层上添加part类名就行了
            <div class="line"></div>
            <div class="nav">
                <div class="swiper-container">
                    <div class="swiper-wrapper wrapper">
                        <div class="swiper-slide list on">领券下单</div>
                        <div class="swiper-slide list">抽奖赢礼</div>
                        <div class="swiper-slide list">精选囤货</div>
                        <div class="swiper-slide list">半价专区</div>
                        <div class="swiper-slide list">爆款推荐</div>
                        <div class="swiper-slide list">大牌推荐</div>
                        <div class="swiper-slide list">更多福利</div>
                        <div class="swiper-slide list" id="last">特惠专区</div>
                    </div>
    
                    <div class="swiper-pagination"></div>
                    <div class="direction"></div>
                    <div class="direction direction-prev"></div>
                    <div class="direction direction-next"></div>
                </div>
            </div>

    nav导航的css样式

    /*导航 start*/
    .line {
      background-color: #fff;
    }
    .line.move {
      height: 0.8rem;
    }
    .nav {
      margin: 0 auto;
      height: 0.8rem;
      width: 100%;
      line-height: 0.8rem;
      text-align: center;
      background-color: #ffffff;
      z-index: 999;
      position: relative;
      color: #3c0486;
      font-size: 0.28rem;
      max-width: 7.5rem;
    }
    .nav.move {
      position: fixed;
      top: 0;
    }
    .nav.box {
      height: 3rem;
      border-top: 0.03rem solid #8fc1e8;
      width: 0.5rem;
    }
    .nav .swiper-container {
      height: 0.8rem;
    }
    .nav .swiper-slide {
      text-align: center;
      width: auto;
      color: #666666;
      white-space: nowrap;
      padding: 0 0.3rem;
    }
    .nav .swiper-slide.on {
      color: #fe8716;
    }
    /*导航 end*/

    引入的JS代码

    var navSwiper = new Swiper('.nav .swiper-container', {
        slidesPerView: 'auto',
        paginationClickable: true,
        pagination : '.nav .swiper-pagination',
        paginationHide :false,
        nextButton:'.nav .direction-next',
        prevButton:'.nav .direction-prev'
    });
    
    // 双旦狂欢
    // var bashSwiper = new Swiper('.bash-list .swiper-container', {
    //     slidesPerView: 'auto',//一行显示3个
    //     slidesPerColumn: 3,//显示2行
    //     spaceBetween :5,
    // });
    window.onload = function(){
        setTimeout(function() {
            loading();
        }, 600);
    }
    
    function loading(){
        var nowCur = $('.nav .swiper-wrapper div.on').index();
        // console.log(nowCur);
        if (nowCur>3) {
            $('.swiper-pagination .swiper-pagination-bullet').eq(nowCur-1).click();
        }
    }
    
    
    $(window).on( 'scroll' , function(){
        var nowTop = $(window).scrollTop();
        var a = 0;
        $('.part').each(function(){
            var nowIndex = $('.part').index(this);
            var boxTop = $(this).offset().top;
            if( boxTop <= nowTop + $('.nav').height()+10 ){
                a = nowIndex;
            }
        })
        var woca = $('.nav .swiper-wrapper div.on').index();
        
        $('.swiper-pagination span').eq(a).click();
        $('.nav .swiper-wrapper div').removeClass('on').eq(a).addClass('on');
    
        // 瀵艰埅楂樺害
        var lineTop = $('.line').offset().top;
        if( nowTop >= lineTop ){
            $('.nav,.line').addClass('move');
        } else {
            $('.nav,.line').removeClass('move');
        }
    })
    $('.direction').bind('click',function(){
        if( $(this).hasClass('swiper-button-disabled') && $(this).hasClass('direction-next') ){
            // $('.direction-prev').fadeIn(600);
            // $('.direction-next').fadeOut(600);
        } else if ( $(this).hasClass('swiper-button-disabled') && $(this).hasClass('direction-prev')  ) {
            // $('.direction-next').fadeIn(600);
            // $('.direction-prev').fadeOut(600);
        }
    })
    $('.nav .swiper-slide').click(function(){
        var nowIndex = $(this).index();
        $('body,html').animate({'scrollTop':$('.part').eq(nowIndex).offset().top - $('.nav').height() })
    })

    实现的效果:

  • 相关阅读:
    判别模型、生成模型与朴素贝叶斯方法
    git的安装已经连github
    uva 10061 How many zero's and how many digits ?
    Java菜鸟学习笔记()--面向对象篇(七):Wrapper Class包装类
    丁香园技术负责人冯大辉近日在知乎上披露了当年共同创办阿里巴巴的18个合伙人的近况:
    不用派生CTreeCtrl不用繁琐的过程 教你如何让CTreeCtrl的每一项有ToolTip提示
    数据结构排序系列详解之三 冒泡排序
    HDU 4612 (13年多校第二场1002)无向图缩点,有重边
    Mac下cocos2dx3.1用Cocos IDE写的Lua binding篇01
    SECURITY_ATTRIBUTES 设置低权限
  • 原文地址:https://www.cnblogs.com/sauronblog/p/12036634.html
Copyright © 2020-2023  润新知