AlexKondov

Slider

Nov 23rd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( document ).ready(function() {
  2.     var index = 1;
  3.     $('.slide').hide();
  4.     $('#slideshow div:nth-child(1)').show();
  5.  
  6.     window.setInterval(changeSlide, 2000);
  7.  
  8.     $('button#next').on('click', function() {
  9.         changeSlide();
  10.     })
  11.  
  12.     $('button#back').on('click', function() {
  13.         $('#slideshow div:nth-child(' + index + ')').fadeOut();
  14.         index--;
  15.         if (index < 1) {
  16.             index = 3;
  17.         };
  18.         $('#slideshow div:nth-child(' + index + ')').fadeIn();
  19.     })
  20.  
  21.     function changeSlide() {
  22.         $('#slideshow div:nth-child(' + index + ")").fadeOut('slow');
  23.         index++;
  24.         if (index > 3) {
  25.             index = 1;
  26.         };
  27.         $('#slideshow div:nth-child(' + index + ")").fadeIn('slow');
  28.     }
  29.  
  30. });
Advertisement
Add Comment
Please, Sign In to add comment