I'm using bootstrap tab & swiper slider,I have multiples tab, in all tabs have image slider. The swiper slider is working fine except pagination in first tab but another tab, both are not working.
Basically i am doing phone-gap project. In this project requirement is that image slider into tab pane.
Here is my code.
HTML
<div class="container">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="active">
<a href="#Apparel" role="tab" data-toggle="tab">
<i class="fa fa-home"></i> Apparel
</a>
</li>
<li>
<a href="#Electronic" role="tab" data-toggle="tab">
<i class="fa fa-user"></i> Electronic
</a>
</li>
<li>
<a href="#Furniture" role="tab" data-toggle="tab">
<i class="fa fa-envelope"></i> Furniture
</a>
</li>
<li>
<a href="#Mobile" role="tab" data-toggle="tab">
<i class="fa fa-cog"></i> Mobile
</a>
</li>
</ul>
</div>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane fade active in" id="Apparel">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Apparel Image 1</div>
<div class="swiper-slide">Apparel Image 2</div>
<div class="swiper-slide">Apparel Image 3</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
<div class="tab-pane fade" id="Electronic">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Electronic Image 1</div>
<div class="swiper-slide">Electronic Image 2</div>
<div class="swiper-slide">Electronic Image 3</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
<div class="tab-pane fade" id="Furniture">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Furniture Image 1</div>
<div class="swiper-slide">Furniture Image 2</div>
<div class="swiper-slide">Furniture Image 3</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
<div class="tab-pane fade" id="Mobile">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Mobile Phone Image 1</div>
<div class="swiper-slide">Mobile Phone Image 2</div>
<div class="swiper-slide">Mobile Phone Image 3</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
</div>
</div>
</div>
Javascript
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
paginationClickable: true,
spaceBetween: 30,
autoplay: 2500,
});
Here is my Example FIDDLE
Please help me....
Add the below code with the swiper initialisation
observer: true,
observeParents: true,
Actually, I had the same problem. Add a class-name to the ul-tag. Swiper must be reinitialized:
$(".class-name li").on("click",function(){
reinitializeSwiper(swiper);
});
function reinitializeSwiper(swiper) {
setTimeout(function () {
swiper.update();
}, 400);
}
you must create a simple listener for the shown.bs.tab event and then use update() method.
var mySwiper = new Swiper('.swiper-container', {
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
var paneTarget = $(e.target).attr('href');
var $thePane = $('.tab-pane' + paneTarget);
var paneIndex = $thePane.index();
if ($thePane.find('.swiper-container').length > 0 && 0 === $thePane.find('.swiper-slide-active').length) {
mySwiper[paneIndex].update();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With