Find reference to Swiper from the DOM

0

I have several swiper on my page,

  

link

which are created dynamically. I need to do a slideTo by clicking on some buttons outside the swper. These banners will know the DOM object that corresponds to the swiper-wrapper and an attribute to know which slide it should be sent to.

I can not find a way to get the instance of the javascript object swiper thing, then I can do a mySwiper.slideTo (indexSlide);

    
asked by Pablo 01.05.2018 в 15:06
source

1 answer

0

On the page you share from Swiper, it says there how to get the reference to that object:

var mySwiper = document.querySelector('.swiper-container').swiper

In your case, it would be to change the .swiper-container selector to one that specifically identifies the dynamically generated swiper from which the external button was triggered. If you need help with that, share the HTML to see how it should be:)

  

After you initialize Swiper it is possible to access to Swiper's   instance on its HTMLElement. It is swiper property of Swiper's HTML   container element:

var mySwiper = document.querySelector('.swiper-container').swiper

// Now you can use all slider methods like
mySwiper.slideNext();
    
answered by 04.05.2018 в 06:29