基于swiper的縮略圖輪播

效果圖示.jpg

首先引入swiper

 <link rel="stylesheet" href="resources/swiper-4.4.1/css/swiper.css">
<script type="text/javascript" src="resources/swiper-4.4.1/js/swiper.min.js"></script>

html部分

<div class="pc-slide">
    <div class="view">
        <div class="swiper-container">
            <a class="arrow arrow-left" href="#"></a>
            <a class="arrow arrow-right" href="#"></a>
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <a target="_blank"><img src="resources/images/big-1.png" alt=""></a>
                </div>
                <div class="swiper-slide">
                    <a target="_blank"><img src="resources/images/big-2.png" alt=""></a>
                </div>
                <div class="swiper-slide">
                    <a target="_blank"><img src="resources/images/big-3.png" alt=""></a>
                </div>
                <div class="swiper-slide">
                    <a target="_blank"><img src="resources/images/big-4.png" alt=""></a>
                </div>
                <div class="swiper-slide">
                    <a target="_blank"><img src="resources/images/big-5.png" alt=""></a>
                </div>
            </div>
        </div>
    </div>
    <div class="preview">
        <a class="arrow arrow-left" href="#"></a>
        <a class="arrow arrow-right" href="#"></a>
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide active-nav">
                    <img src="resources/images/small-01.png" alt="">
                </div>
                <div class="swiper-slide">
                    <img src="resources/images/small-02.png" alt="">
                </div>
                <div class="swiper-slide">
                    <img src="resources/images/small-03.png" alt="">
                </div>
                <div class="swiper-slide">
                    <img src="resources/images/small-04.png" alt="">
                </div>
                <div class="swiper-slide">
                    <img src="resources/images/small-05.png" alt="">
                </div>
            </div>
        </div>
    </div>
</div>

css樣式部分

.view .swiper-container { height: 620px;width: 100%; }
.view:hover .arrow{display: block;}
.view .arrow{display: none;position: absolute;top: 50%;margin-top: -35px;width: 70px;height: 70px;z-index: 10; }
.view .arrow-left {background: url("../images/culture/pre.png") no-repeat center; left: 10px;}
.view .arrow-right {background: url("../images/culture/next.png") no-repeat center; right: 10px;}
.preview { padding: 0 30px;width: 100%;margin-top: 10px;position: relative;}
.preview .swiper-slide {padding: 0 12px;width: 23%;height: 100%;}
.preview .arrow{position: absolute;top: 50%;margin-top: -9px;width: 9px; height: 18px;z-index: 10;}
.preview .arrow-left {background: url("../images/culture/arrow-left.png") no-repeat center;left: 10px;}
.preview .arrow-right {background: url("../images/culture/arrow-right.png") no-repeat center;right: 10px;}
.preview img {padding: 1px;}
.preview .active-nav img {padding: 0;border: 1px solid #FF3E3E;}

js部分

    var viewSwiper = new Swiper('.view .swiper-container', {
        autoplay: {
            delay: 4500,
            disableOnInteraction: false,
        },
        on:{
            slideChangeTransitionStart: function() {
                updateNavPosition()
            }
        }
    });

    $('.view .arrow-left,.preview .arrow-left').on('click', function(e) {
        e.preventDefault();
        if (viewSwiper.activeIndex == 0) {
            viewSwiper.slideTo(viewSwiper.slides.length - 1, 1000);
            return
        }
        viewSwiper.slidePrev()
    });
    $('.view .arrow-right,.preview .arrow-right').on('click', function(e) {
        e.preventDefault();
        if (viewSwiper.activeIndex == viewSwiper.slides.length - 1) {
            viewSwiper.slideTo(0, 1000);
            return
        }
        viewSwiper.slideNext()
    });

    var previewSwiper = new Swiper('.preview .swiper-container', {
        //visibilityFullFit: true,
        slidesPerView: '3.7',
        allowTouchMove: false,
        on:{
            tap: function() {
                viewSwiper.slideTo(previewSwiper.clickedIndex)
            }
        }
    });

    function updateNavPosition() {
        $('.preview .active-nav').removeClass('active-nav');
        var activeNav = $('.preview .swiper-slide').eq(viewSwiper.activeIndex).addClass('active-nav');
        if (!activeNav.hasClass('swiper-slide-visible')) {
            if (activeNav.index() > previewSwiper.activeIndex) {
                var thumbsPerNav = Math.floor(previewSwiper.width / activeNav.width()) - 1;
                previewSwiper.slideTo(activeNav.index() - thumbsPerNav)
            } else {
                previewSwiper.slideTo(activeNav.index())
            }
        }
    }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 28,811評(píng)論 1 45
  • 1 Webpack 1.1 概念簡(jiǎn)介 1.1.1 WebPack是什么 1、一個(gè)打包工具 2、一個(gè)模塊加載工具 3...
    Kevin_Junbaozi閱讀 7,022評(píng)論 0 16
  • 問(wèn)答題47 /72 常見(jiàn)瀏覽器兼容性問(wèn)題與解決方案? 參考答案 (1)瀏覽器兼容問(wèn)題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 14,145評(píng)論 1 92
  • 不喜歡一個(gè)人獨(dú)處的原因,腦中人太多,事更是如此。不喜歡熱鬧的原因,人心在那一刻看的實(shí)實(shí)在在清楚。 歸根是自己的原因...
    千林閱讀 281評(píng)論 0 0
  • 在這個(gè)靠人脈和實(shí)力吃飯的世界,身邊的朋友實(shí)在太重要了,一定要擦亮眼睛交朋友,否則傷心費(fèi)時(shí)! 第一種女孩非常單純的女...
    寫(xiě)好字做好人閱讀 812評(píng)論 0 1

友情鏈接更多精彩內(nèi)容