Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iDangerous Swiper, thumbnail control

Tags:

html

jquery

I’m a beginner coder. Does anybody know how to link thumbnail images to the swiper so that clicking a thumbnail moves the swiper-container to the corresponding slide? Thanks for your help!

Example: http://markdarren.com/F13/test.html

    <div class="swiper-container">  
    <div class="swiper-wrapper">
          <div class="swiper-slide"><img src="images/jacket2.png"></div>
          <div class="swiper-slide"><img src="images/jacket3.png"></div>
          <div class="swiper-slide"><img src="images/jacket4.png"></div>
          <div class="swiper-slide"><img src="images/jacket5.png"></div>
      </div>
    </div>        
    <div class="thumb">
      <div><a href="" title="onClick goto jacket 2"><img src="images/jacket2.png"></a></div>
      <div><a href="" title="onClick goto jacket 3"><img src="images/jacket3.png"></a></div>
      <div><a href="" title="onClick goto jacket 4"><img src="images/jacket4.png"></a></div>
      <div><a href="" title="onClick goto jacket 5"><img src="images/jacket5.png"></a></div>
    </div>     
    <script src="js/scroller/js/jquery-1.10.1.min.js"></script>
    <script src="js/scroller/js/idangerous.swiper-2.0.min.js"></script>
    <script>
    var mySwiper = new Swiper('.swiper-container',{
    pagination: '.pagination',
    paginationClickable: true
    })
    </script>
like image 534
mooie Avatar asked Jan 14 '23 00:01

mooie


1 Answers

Change everything in your script tag to:

$(document).ready(function() {

    var mySwiper = new Swiper('.swiper-container',{
        pagination: '.pagination',
        paginationClickable: true
    });

    $(".thumb").on('click', 'div', function(){
        mySwiper.slideTo($(this).index(), 500);
    });
});

The bit I've added isn't tested, but should mean that on a click on one of the divs in your .thumbs bit (I'm ignoring your a tags) will swipe to the index of that div (e.g. is it div 1, div 2 etc).

like image 163
Rich Bradshaw Avatar answered Jan 20 '23 18:01

Rich Bradshaw