WTE
WTE

Reputation: 331

Swiper - Reinitialise once image loaded

Need some clarification regard swiper plugin. Used in other pages, it works fine. Only on particular page, we are updating image manually to change based on user preference. Once Image is changed, we need initalize the Swiper carosuel.

Tried in multiple way with swiper.init() or destroy(true, true). But its not initalize the component. Not sure whether this plugin wont support this logic.

Whether we can init swiper like below and verify in browser console.

var swiper = new Swiper('.swiper-container'){
          loop: true,
          slidesPerView: 1,
          autoplay: 2000
        }

setTimeout(function() { swiper.init(); },10000);

Upvotes: 0

Views: 1241

Answers (1)

Ari Shojaei
Ari Shojaei

Reputation: 359

Put swiper instance in a function and use that function when you want to init swiper.

function initSwiper() {
 new Swiper('.swiper-container'){
  loop: true,
  slidesPerView: 1,
  autoplay: 2000
 }
};

initSwiper();

Upvotes: 1

Related Questions