如何在iDangerous Swiper中滑动加载数据?

时间:2016-09-07 14:10:54

标签: javascript jquery slider

我正在使用iDangerous Swiper移动滑块。一切都很好,但是当用户滑动到特定滑块div时,我不知道如何在滑块中加载数据。简而言之,我想在滑动时加载数据。

请检查代码段。

另一个问题是我还想加载数据点击链接,在这种情况下" 滑到3 "。我想使用data-post检索帖子的ID,然后我想在当前滑块div中加载一些Ajax数据。

所以基本上我需要点击链接幻灯片到特定的滑块,然后使用链接属性加载数据。之后,如果用户滑动到另一张幻灯片,那么我想在该幻灯片中加载其他数据。

我知道这令人困惑,真的很抱歉英语。 :(

谢谢



var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        slideToClickedSlide:true,
        loop: true,
        preloadImages: false,
        lazyLoading: true
    });
    
    $('#btn').click(function(){
    var slider = $(this).data("slider");
swiper.slideTo(slider, 1000, false);
})

html, body {
        position: relative;
        height: 100%;
    }
    body {
        background: #eee;
        font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
        font-size: 14px;
        color:#000;
        margin: 0;
        padding: 0;
    }
    .swiper-container {
        width: 100%;
        height: 100%;
    }
    .swiper-slide {
        text-align: center;
        font-size: 18px;
        background: #fff;
        /* Center slide text vertically */
        display: -webkit-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-pack: center;
        -ms-flex-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-box-align: center;
        -ms-flex-align: center;
        -webkit-align-items: center;
        align-items: center;
    }

<link href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/css/swiper.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.3.1/js/swiper.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Swiper -->
    <div class="swiper-container">
        <div>
    <a href="#" id="btn" data-slider="3" data-post="234"> Slide to 3</a>
    </div>
        <div class="swiper-wrapper">
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
            <div class="swiper-slide">Slide 4</div>
            <div class="swiper-slide">Slide 5</div>
            <div class="swiper-slide">Slide 6</div>
            <div class="swiper-slide">Slide 7</div>
            <div class="swiper-slide">Slide 8</div>
            <div class="swiper-slide">Slide 9</div>
            <div class="swiper-slide">Slide 10</div>
        </div>
        <!-- Add Pagination -->
        
        <div class="swiper-pagination"></div>

    </div>
&#13;
&#13;
&#13;

0 个答案:

没有答案