I am using tippy.js
and swiper.js
.
I am setting Tippy up as such:
tippy('.tippy', {
allowHTML: true,
theme: 'light div lg',
offset: [0, 16],
});
This works fine.
However, I would like to close/hide tippy instances when a swiper.js has a slideChange
event.
On my swiper init file I have:
window['swiper_'+id].on('slideChange', function () {
console.log('slide changed');
const thisTippy = tippy($('.tippy'));
thisTippy.hide();
});
But of course this doesn’t work.
Would anyone know how I could access the tippy instance from within the my swiper?
2
Answers
You need to target that particular tooltip’s instance. Something like this:
Docs
The
slideChange
event exposes theswiper
instance. With that instance you can get the current slide element. From there you can traverse the slide element and look for your tippy element.Store the
tippy
instance in a variable to be able to close it whenever you get to the next slide.