Advertisement
Guest User

slider JS

a guest
Jun 21st, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Status of the slider.
  2. var active = 0;
  3.  
  4. //Rest period between each tansition.
  5. var rest = 0;
  6.  
  7. //Position of the current division.
  8. var position = 0;
  9.  
  10. //Total number of divisions.
  11. var div_total = 7;
  12.  
  13. //Current slider number.
  14. var slide_num = 1;
  15.  
  16. //The current divisons name.
  17. var current_div;
  18.  
  19. //The last division used.
  20. var last_div;
  21.  
  22. //The fucntion is used to animate the slider divisions.
  23. function slidemenus() {
  24.    
  25.     //Set the current division.
  26.     current_div = "slider" + slide_num;
  27.    
  28.     //Check if the slider number is greater than one
  29.     //if it is set the last_div variable to slide_num - 1
  30.     if (slide_num > 1) {
  31.         last_div = "slider" + (slide_num - 1)
  32.    
  33.     //Else if the slider division is not greater than 1
  34.     //set the last_div to 1.
  35.     } else {
  36.         last_div = "slider1";
  37.     }
  38.    
  39.     //If the slider is active then get the position of the
  40.     //current division and animate it.
  41.     if (active == 1) {
  42.         position = parseInt(document.getElementById(current_div).offsetLeft);      
  43.  
  44.         //If the current divisions left property is less
  45.         //than 0 move it across 10px;
  46.         if (position < 0) {
  47.             position = position + 10;
  48.             document.getElementById(current_div).style.left = position;
  49.         } else {
  50.            
  51.             //Disable the slider
  52.             active = 0;
  53.            
  54.             //Increase the slider number if it has
  55.             //not exceeded the div_total.
  56.             if(slide_num <= div_total) {
  57.                 slide_num = slide_num + 1;
  58.            
  59.             //Else if the slide_num has exceeded the
  60.             //div_total reset it to 1 and change the
  61.             //zindexes of the divisions.
  62.             } else {
  63.                 document.getElementById("slider1").style.zIndex = 1;
  64.                 document.getElementById(last_div).style.zIndex = 2;
  65.                 slide_num = 1;
  66.             }
  67.            
  68.             //Clear the rest interval
  69.             clearInterval(rest);
  70.             rest = setInterval("slidemenus()", 9000);
  71.            
  72.         }
  73.     //Else if the slider is not active enable it and reset
  74.     //all of the divisions zindexes.
  75.     } else {
  76.         active = 1;
  77.         document.getElementById("slider1").style.zIndex = 1;
  78.         document.getElementById("slider2").style.zIndex = 1;
  79.         document.getElementById("slider3").style.zIndex = 1;
  80.         document.getElementById("slider4").style.zIndex = 1;
  81.         document.getElementById("slider5").style.zIndex = 1;
  82.         document.getElementById("slider6").style.zIndex = 1;
  83.         document.getElementById("slider7").style.zIndex = 1;
  84.         document.getElementById(last_div).style.zIndex = 2;
  85.         document.getElementById(current_div).style.zIndex = 3;
  86.         document.getElementById(current_div).style.left = -600;
  87.  
  88.         clearInterval(rest);
  89.         rest = setInterval("slidemenus()", 20);
  90.     }
  91.    
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement