Posted By

Jamie on 07/31/10


Tagged

delay slidedeck autoplay


Versions (?)

SlideDeck AutoPlay Functionality with First Slide Delay


 / Published in: JavaScript
 

URL: http://getsatisfaction.com/slidedeck/topics/slide_time

  1. var loopingInterval;
  2. var mySlideDeck = jQuery('.slidedeck').slidedeck();
  3. mySlideDeck.vertical();
  4. var interval = 1000;
  5. var firstDelay = 3000;
  6.  
  7.  
  8. // initialize an autoplay switch
  9. var autoPlay = false;
  10. var autoPlayLoop = true;
  11.  
  12. function autoPlayAdvanceLoop(){
  13. if(autoPlay){
  14. // Check to see if the current slide is the last slide
  15. if(mySlideDeck.current == mySlideDeck.slides.length && autoPlayLoop == true){
  16. // This is the last slide, go to the first slide
  17. mySlideDeck.goTo(1);
  18. } else {
  19. // This is not the last slide, go to the next slide
  20. mySlideDeck.next();
  21. }
  22. }
  23. }
  24.  
  25. // sets an initial delay
  26. setTimeout(function(){
  27. loopingInterval = setInterval(autoPlayAdvanceLoop,interval); // Run the autoPlayAdvanceLoop() function every interval milliseconds
  28. }, firstDelay - interval)
  29.  
  30. autoPlay = true;
  31.  
  32. // Stop autoPlay if the deck is clicked.
  33. jQuery('.slidedeck').click(function(){
  34. autoPlay = false;
  35. clearInterval(loopingInterval);
  36. });

Report this snippet  

You need to login to post a comment.