Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tabsSlider(tabs, tabsWrap, tabsContainer, tabLeft, tabRight){
- var wii = [];
- var tabsConW = 0;
- var clickCount = 0;
- var mLeft = 0;
- jQuery.each(tabs, function(){
- wii.push($(this).width());
- });
- for ( i=0; i<wii.length; i++) {
- tabsConW += wii[i];
- }
- if (tabsConW + 16 <= tabsWrap.width()) {
- tabToLeft.hide();
- tabToRight.hide();
- }
- tabsContainer.css("width", tabsConW + 16 + "px");
- var stopSlide = tabsContainer.width() - tabsWrap.outerWidth();
- tabRight.click(function(event){
- event.preventDefault();
- mLeft = mLeft + 3 + wii[clickCount];
- if (mLeft <= stopSlide) {
- tabsContainer.animate({ "margin-left": '-' + mLeft + 'px'}, 500);
- clickCount++;
- } else {
- mLeft = stopSlide;
- tabsContainer.animate({ "margin-left": '-' + mLeft + 'px'}, 500);
- $(this).css("visibility", "hidden");
- clickCount = wii.length;
- }
- tabLeft.css("visibility", "visible");
- });
- tabLeft.click(function(event){
- event.preventDefault();
- if (clickCount === wii.length){
- mLeft = mLeft - 3 - wii[clickCount-1];
- tabsContainer.animate({ "margin-left": '-' + mLeft + 'px'}, 500);
- clickCount--;
- } else if (clickCount === 0) {
- var offsetCont = tabsContainer.offset();
- var offsetWrap = tabsWrap.offset();
- var diffOffset = parseInt((offsetWrap.left - offsetCont.left), 10);
- var tabsWidthSum = wii[0];
- for ( i = 0; i < wii.length; i++ ) {
- // console.log(wii.length);
- if (diffOffset <= tabsWidthSum) {
- // console.log( diffOffset + ' <= ' +tabsWidthSum + ' fdfdf ');
- } else {
- tabsWidthSum = tabsWidthSum + wii[i+1];
- // console.log(i);
- clickCount = i;
- }
- // console.log(clickCount);
- }
- } else {
- if (mLeft <= wii[clickCount-1]) {
- tabsContainer.animate({ "margin-left": '0px'}, 500);
- clickCount = 0;
- mLeft = 0;
- } else {
- mLeft = mLeft - 3 - wii[clickCount-1];
- tabsContainer.animate({ "margin-left": '-' + mLeft + 'px'}, 500);
- clickCount--;
- }
- }
- tabRight.css("visibility", "visible");
- if (clickCount === 0) {
- $(this).css("visibility", "hidden");
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement