$(function(){ var viewswiper = new swiper('.view .swiper-container', { onslidechangestart: function() { updatenavposition() } }); $('.view .swiper-button-prev,.preview .arrow-left').on('click', function(e) { e.preventdefault() if (viewswiper.activeindex == 0) { viewswiper.slideto(viewswiper.slides.length - 1, 1000); return } viewswiper.slideprev() }) $('.view .swiper-button-next,.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: 'auto', allowtouchmove: false, ontap: 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()) } } } });