Advertisement
artursn

Untitled

Jul 9th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tabsSlider(tabs, tabsWrap, tabsContainer, tabLeft, tabRight){
  2.  
  3.         var wii = [];
  4.         var tabsConW = 0;
  5.         var clickCount = 0;
  6.         var mLeft = 0;
  7.         jQuery.each(tabs, function(){
  8.             wii.push($(this).width());
  9.         });
  10.  
  11.  
  12.         for ( i=0; i<wii.length; i++) {
  13.             tabsConW += wii[i];
  14.         }
  15.  
  16.         if (tabsConW + 16 <= tabsWrap.width()) {
  17.             tabToLeft.hide();
  18.             tabToRight.hide();
  19.         }
  20.  
  21.         tabsContainer.css("width", tabsConW + 16 + "px");
  22.  
  23.         var stopSlide = tabsContainer.width() - tabsWrap.outerWidth();
  24.  
  25.         tabRight.click(function(event){
  26.             event.preventDefault();
  27.             mLeft = mLeft + 3 + wii[clickCount];
  28.             if (mLeft <= stopSlide) {
  29.                 tabsContainer.animate({ "margin-left": '-' +  mLeft + 'px'}, 500);
  30.                 clickCount++;
  31.             } else {
  32.  
  33.                 mLeft = stopSlide;
  34.  
  35.                 tabsContainer.animate({ "margin-left": '-' +  mLeft + 'px'}, 500);
  36.                 $(this).css("visibility", "hidden");
  37.                 clickCount = wii.length;
  38.             }
  39.  
  40.             tabLeft.css("visibility", "visible");
  41.         });
  42.  
  43.         tabLeft.click(function(event){
  44.             event.preventDefault();
  45.             if (clickCount === wii.length){
  46.                 mLeft = mLeft - 3 - wii[clickCount-1];
  47.                 tabsContainer.animate({ "margin-left": '-' + mLeft  + 'px'}, 500);
  48.                 clickCount--;
  49.             } else if (clickCount === 0) {
  50.                 var offsetCont = tabsContainer.offset();
  51.                 var offsetWrap = tabsWrap.offset();
  52.                 var diffOffset = parseInt((offsetWrap.left - offsetCont.left), 10);
  53.                 var tabsWidthSum = wii[0];
  54.  
  55.                 for ( i = 0; i < wii.length; i++ ) {
  56. //                    console.log(wii.length);
  57.                     if (diffOffset <= tabsWidthSum) {
  58. //                        console.log( diffOffset + ' <= ' +tabsWidthSum + '   fdfdf ');
  59.                     } else {
  60.                         tabsWidthSum = tabsWidthSum + wii[i+1];
  61. //                        console.log(i);
  62.                         clickCount = i;
  63.                     }
  64.  
  65. //                    console.log(clickCount);
  66.                 }
  67.  
  68.             } else {
  69.  
  70.                 if (mLeft <= wii[clickCount-1]) {
  71.                     tabsContainer.animate({ "margin-left": '0px'}, 500);
  72.                     clickCount = 0;
  73.                     mLeft = 0;
  74.                 } else {
  75.                     mLeft = mLeft - 3 - wii[clickCount-1];
  76.                     tabsContainer.animate({ "margin-left": '-' + mLeft  + 'px'}, 500);
  77.                     clickCount--;
  78.                 }
  79.             }
  80.  
  81.             tabRight.css("visibility", "visible");
  82.             if (clickCount === 0) {
  83.                 $(this).css("visibility", "hidden");
  84.             }
  85.  
  86.         });
  87.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement