How to make impress.js slideshow auto play and loop
Asked Answered
G

1

6

I have a slideshow I'd like to auto play and loop continuously. I've found snippets that let me set a global slide duration and use impress.next() with a setInterval() call to move forward, but then I lose the ability to have different durations for each slide.

Gastelum answered 27/7, 2012 at 18:59 Comment(0)
G
26

I'm happy to share my solution. If you see room for improvement don't be shy. Hopefully this helps someone out there.

<script>
  var impress = impress();
  impress.init();

  document.addEventListener('impress:stepenter', function(e){
    if (typeof timing !== 'undefined') clearInterval(timing);
    var duration = (e.target.getAttribute('data-transition-duration') ? e.target.getAttribute('data-transition-duration') : 2000); // use the set duration or fallback to 2000ms
    timing = setInterval(impress.next, duration);
  });
</script>
Gastelum answered 27/7, 2012 at 18:59 Comment(2)
very helpful saved lots of time. +1 for this :)Builtup
Thanks! This got me going in the right direction. However, I did run into some problems. Using custom data-transition-duration on multiple steps, it was hard to get the slideshow to slow down after using a short duration. For me, replacing setInterval(impress.next,duration) with setTimeout(impress.next, duration) would cause the slideshow to behave in the way I wanted it to.Comptom

© 2022 - 2024 — McMap. All rights reserved.