ganlanyuan / tiny-slider

Vanilla javascript slider for all purposes.
MIT License
5.24k stars 786 forks source link

How to intercept item with index 0 (zero) #842

Open smurfxx opened 6 months ago

smurfxx commented 6 months ago

Issue description:
I have an autoplay tiny slide with a timeout of 10 seconds but I'd like to set a timeout of 20 seconds only for the first slide, in other words the slide with index 0.

I tried with the 'indexChanged' event but since it is the first slide, the event only occurs from the second slide onwards. I also tried with the 'onInit' property but the latter only occurs at the beginning of the slide and not after a loop. So what is the ideal method to intercept the first slide on start and on every loop?

This is an example of my code:

var slider = tns({
    container: '.view-slidefarmacia .view-content',
    items: 1,
    slideBy: 1,
    loop: true,
    autoplay: true,
    autoplayTimeout: 10000,
    speed: 400,
    gutter: 0,
    mouseDrag: false,
    touch: true,
    nav: false,
    freezable: false,
    controls: false,
    animateIn: "fadeIn",
    animateOut: "fadeOut",
    mode: "gallery"
});

slider.events.on('indexChanged', function(info, eventName) {
    console.log(info.index); // --> this never returns me the index 0
});

Tiny-slider version: 2.9.4