dynamicweb / swiffy-slider

Super fast carousel and slider with touch for optimized websites running in modern browsers.
MIT License
250 stars 29 forks source link

Playing next slide when video in slider is ended #64

Closed alexpeto closed 2 years ago

alexpeto commented 2 years ago

Hello! I like this slider. I managed to use it in my project but wanted to automatically play next slide only when video is ended or paused, but I couldn't figure out how to achieve this. I am asking: how can this be done? Thank you!

nicped commented 2 years ago

You have to not use the autoplay function - you can then listen to when your video object has ended and then call .slide on the Swiffy slider:

document.getElementById('myVideo').addEventListener('ended',myHandler,false);
    function myHandler(e) {
        // What you want to do after the event
       swiffyslider.slide(document.getElementById('mySwiffyslider'), next = true);
    }

If you want it to autoplay all slides and stay on the video as long as it plays, you need some more script - you need the above for video slides and then combine it with a timer like below for the rest.

setInterval(() => swiffyslider.slide(sliderElement), 2500);

BR Nicolai

alexpeto commented 2 years ago

thank you. it worked!