My motive is when the display size will be small then the slidesPerView
will be 1. I tried the below way, it's working when I refresh the page. But I want it will work automatically. When the window size will increase automatically the slidesPerView
will be increased, again when the window size will decrease automatically the slidesPerView
will be decreased. Where am I doing the mistake? give me a relevant solution...
swiper.js:
if(window.innerWidth>768){
var swiper = new Swiper(".productSwiper", {
slidesPerView: 3,
spaceBetween: 30
});
}else{
var swiper = new Swiper(".productSwiper", {
slidesPerView: 1
});
}
index.html:
<div class="swiper productSwiper my-5">
<div class="swiper-wrapper col-6 col-md-5 col-lg-3">
<div class="swiper-slide card" style="width: 18rem;">
<div class="d-flex justify-content-center">
<img src="static/1_medicine/2.jpg" class="card-img-top product_img d-block py-3" alt="product image 1">
</div>
</div>
</div>
</div>
Note: I used this slider: https://swiperjs.com/demos#slides-per-view