admin管理员组

文章数量:1201647

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.

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.

Share Improve this question asked Jul 27, 2012 at 18:59 creativetimcreativetim 1,1382 gold badges13 silver badges26 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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>

本文标签: javascriptHow to make impressjs slideshow auto play and loopStack Overflow