Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make impress.js slideshow auto play and loop

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.

like image 419
creativetim Avatar asked Jul 27 '12 18:07

creativetim


1 Answers

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>
like image 155
creativetim Avatar answered Oct 13 '22 17:10

creativetim