Advertisement
ostyleo

Untitled

May 1st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var width = 740;
  2. var animationSpeed = 1000;
  3. var pause = 3000;
  4. var currentSlide = 1;
  5. var interval;
  6. var timer;
  7.  
  8. function slide() {
  9.     timer = function () {
  10.         interval = setInterval(function () {
  11.             if(currentSlide === $("#slides").children().length) width = 0;
  12.             else width = 740;
  13.             $("#slides").animate({'margin-left': '-=' + width}, animationSpeed, function () {
  14.                 if (++currentSlide > $("#slides").children().length) {
  15.                     currentSlide = 1;
  16.                     $("#slides").animate({'margin-left': 0}, animationSpeed);
  17.                     clearInterval(interval);
  18.                     timer();
  19.                 }
  20.             });
  21.         }, pause);
  22.     }
  23. }
  24.  
  25. function next() {
  26.     console.log("Going forward:" + currentSlide,$("#slides").children().length - 1);
  27.     if (currentSlide <= $("#slides").children().length - 1) {
  28.         $("#slides").animate({'margin-left': '-=' + width}, animationSpeed, function () {
  29.             currentSlide += 1;
  30.         });
  31.         clearInterval(interval);
  32.         timer();
  33.     }
  34.  
  35. }
  36.  
  37. function previous() {
  38.     console.log("Going back:" + currentSlide,$("#slides").children().length - 1);
  39.     if (currentSlide >= $("#slides").children().length - 1) {
  40.         $("#slides").animate({'margin-left': '+=' + width}, animationSpeed, function () {
  41.             currentSlide -= 1;
  42.         });
  43.         clearInterval(interval);
  44.         timer();
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement