SHARE
TWEET

current js (ether)

a guest Feb 8th, 2016 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.  
  3.   var current = 0;
  4.  
  5.   function previousIndex() {
  6.     var previous = current - 1;
  7.     if (previous == -1) {
  8.       previous = $(".tour-panel").size() - 1;
  9.     }
  10.     return previous;
  11.   }
  12.  
  13.   function nextIndex() {
  14.     var next = current + 1;
  15.     if (next == $(".tour-panel").size()) {
  16.       next = 0;
  17.     }
  18.     return next;
  19.   }
  20.  
  21.   function removeClasses() {
  22.     $(".tour-panel").each(function(index) {
  23.       if (index != current) {
  24.         $(this).removeClass("active-tour fadeInRight fadeInLeft fadeOutRight fadeOutLeft");
  25.       }
  26.     })
  27.   }
  28.  
  29.   function nextElement() {
  30.     removeClasses();
  31.     $($(".tour-panel")[current]).addClass("fadeOutLeft");
  32.     current = nextIndex();
  33.     setTimeout(function() {
  34.       $($(".tour-panel")[current]).addClass("active-tour fadeInRight");
  35.     }, 50);
  36.     setTimeout(function() {
  37.       $($(".tour-panel")[previousIndex()]).removeClass("active-tour fadeOutLeft");
  38.     }, 750);
  39.     console.log(current);
  40.   }
  41.  
  42.   function previousElement() {
  43.     removeClasses();
  44.     $($(".tour-panel")[current]).addClass("fadeOutRight");
  45.     current = previousIndex();
  46.     setTimeout(function() {
  47.       $($(".tour-panel")[current]).addClass("active-tour fadeInLeft");
  48.     }, 50);
  49.     setTimeout(function() {
  50.       $($(".tour-panel")[nextIndex()]).removeClass("active-tour fadeOutRight");
  51.     }, 750);
  52.   }
  53.  
  54.  
  55.     $('.slideshow-timeline a').click(function() {
  56.     var target_id = $(this).attr('href');
  57.     removeClasses();
  58.     $($(".tour-panel")[current]).addClass("fadeOutLeft");
  59.     current = parseInt(target_id.split('-')[1]) || 0;           // change here
  60.     setTimeout(function() {
  61.       $($(".tour-panel")[current]).addClass("active-tour fadeInRight");
  62.     }, 50);
  63.   });
  64.  
  65.  
  66.   Mousetrap.bind('left', previousElement);
  67.   Mousetrap.bind('right', nextElement);
  68.  
  69.   $(".previous").click(previousElement);
  70.   $(".next").click(nextElement);
  71. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top