基于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)容合作請聯(lián)系作者
  • 序言:七十年代末簇宽,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子吧享,更是在濱河造成了極大的恐慌魏割,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,252評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件钢颂,死亡現(xiàn)場離奇詭異钞它,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)殊鞭,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,886評論 3 399
  • 文/潘曉璐 我一進(jìn)店門遭垛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人操灿,你說我怎么就攤上這事锯仪。” “怎么了趾盐?”我有些...
    開封第一講書人閱讀 168,814評論 0 361
  • 文/不壞的土叔 我叫張陵庶喜,是天一觀的道長幌蚊。 經(jīng)常有香客問我,道長溃卡,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,869評論 1 299
  • 正文 為了忘掉前任蜒简,我火速辦了婚禮瘸羡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘搓茬。我一直安慰自己犹赖,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 68,888評論 6 398
  • 文/花漫 我一把揭開白布卷仑。 她就那樣靜靜地躺著峻村,像睡著了一般。 火紅的嫁衣襯著肌膚如雪锡凝。 梳的紋絲不亂的頭發(fā)上粘昨,一...
    開封第一講書人閱讀 52,475評論 1 312
  • 那天,我揣著相機(jī)與錄音窜锯,去河邊找鬼张肾。 笑死,一個胖子當(dāng)著我的面吹牛锚扎,可吹牛的內(nèi)容都是我干的吞瞪。 我是一名探鬼主播,決...
    沈念sama閱讀 41,010評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼驾孔,長吁一口氣:“原來是場噩夢啊……” “哼芍秆!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起翠勉,我...
    開封第一講書人閱讀 39,924評論 0 277
  • 序言:老撾萬榮一對情侶失蹤妖啥,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后眉菱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體迹栓,經(jīng)...
    沈念sama閱讀 46,469評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,552評論 3 342
  • 正文 我和宋清朗相戀三年俭缓,在試婚紗的時候發(fā)現(xiàn)自己被綠了克伊。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,680評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡华坦,死狀恐怖愿吹,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情惜姐,我是刑警寧澤犁跪,帶...
    沈念sama閱讀 36,362評論 5 351
  • 正文 年R本政府宣布椿息,位于F島的核電站,受9級特大地震影響坷衍,放射性物質(zhì)發(fā)生泄漏寝优。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,037評論 3 335
  • 文/蒙蒙 一枫耳、第九天 我趴在偏房一處隱蔽的房頂上張望乏矾。 院中可真熱鬧,春花似錦迁杨、人聲如沸钻心。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,519評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽捷沸。三九已至,卻和暖如春狐史,著一層夾襖步出監(jiān)牢的瞬間痒给,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,621評論 1 274
  • 我被黑心中介騙來泰國打工预皇, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留侈玄,地道東北人。 一個月前我還...
    沈念sama閱讀 49,099評論 3 378
  • 正文 我出身青樓吟温,卻偏偏與公主長得像序仙,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子鲁豪,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,691評論 2 361

推薦閱讀更多精彩內(nèi)容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5潘悼? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 27,518評論 1 45
  • 1 Webpack 1.1 概念簡介 1.1.1 WebPack是什么 1爬橡、一個打包工具 2治唤、一個模塊加載工具 3...
    Kevin_Junbaozi閱讀 6,678評論 0 16
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 13,760評論 1 92
  • 不喜歡一個人獨處的原因糙申,腦中人太多宾添,事更是如此。不喜歡熱鬧的原因柜裸,人心在那一刻看的實實在在清楚缕陕。 歸根是自己的原因...
    千林閱讀 256評論 0 0
  • 在這個靠人脈和實力吃飯的世界,身邊的朋友實在太重要了疙挺,一定要擦亮眼睛交朋友扛邑,否則傷心費時! 第一種女孩非常單純的女...
    寫好字做好人閱讀 730評論 0 1