I have a SplideJS slider with an amount of slides. I need to perform an action when the last slider is active.
I check documentation but I didn't found any reference to this kind of event so I write a script to acheive that goal but i need some help
My code :
// Class for each slide
const splideSlide = document.querySelector('.splide__slide')
// Check if a next element sibling is available
if(splideSlide.nextElementSibling === undefined) {
console.log("On last, I call aother action")
} else {
console.log("Not last")
}
Going with what @CBroe mentioned in the commends,
activeis the one that might work for you.First thing I'm doing is getting the max index value, so that I'll know which slide is the last one. This could have been handled in other ways (for example
li.splide__slide:nth-childand then getting the index of that one).Next, after initializing the Splide slider, I'm attaching an
activeevent listener, and checking if the currently active slide's index is the same as the index of the lastli.splide__slide.