I m litte bit confused about swiper slides. Couldnt find any solution on stackowerflow at all. I am trying to put same slider in one page even i want to put 5 of them but only one of them works and its the top one. Am i missing anything on js configurations or i shouldnt put same classes on all sliders.
Here is my code;
<div class="section-padding overflow-hidden">
<div class="collections-carousel">
<div class="section-title-wrapper">
<div class="section-title"><span class="gradient-text">Curated</span> Collections</div>
<div class="title-navigation">
<div class="featured-carousel-icon swiper-button-prev"><svg class="crumina-icon">
<use xlink:href="#arrow-left2-icon"></use>
</svg></div>
<div class="featured-carousel-icon swiper-button-next"><svg class="crumina-icon">
<use xlink:href="#arrow-right2-icon"></use>
</svg></div>
</div>
</div>
<div class="featured-carousel">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="collection-item">
<a href="02-explore.html">
<div class="cover-image"><img src="img/content/artworks/artwork-2.png" alt="">
</div>
<div class="collection-info">
<div class="title h3">Pop Culture</div>
<div class="number">364 items</div>
</div>
</a>
</div>
</div>
<div class="swiper-slide">
<div class="collection-item">
<a href="02-explore.html">
<div class="cover-image"><img src="img/content/artworks/artwork-3.png" alt="">
</div>
<div class="collection-info">
<div class="title h3">Motion Graphics</div>
<div class="number">590 items</div>
</div>
</a>
</div>
</div>
<div class="swiper-slide">
<div class="collection-item">
<a href="02-explore.html">
<div class="cover-image"><img src="img/content/artworks/artwork-4.png" alt="">
</div>
<div class="collection-info">
<div class="title h3">Illustrations</div>
<div class="number">364 items</div>
</div>
</a>
</div>
</div>
<div class="swiper-slide">
<div class="collection-item">
<a href="02-explore.html">
<div class="cover-image"><img src="img/content/artworks/artwork-5.png" alt="">
</div>
<div class="collection-info">
<div class="title h3">3D Art</div>
<div class="number">590 items</div>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
When i put same of it the second one just going crazy and also arrow buttons and slide function doesnt work.
2
Answers
Add a class on the whole swiper container to differentiate between each slider, and of course, initialize each.
Demo is taken from the documentation.
You need to initialize each swiper instance e.g using a
forEach
loop:This works pretty well if all your sliders share the same options (e.g slides per view, gaps etc).
You might also store individual parameters in a
data-attribute
and run a generic initializing function