Link to home
Start Free TrialLog in
Avatar of sastry_hora
sastry_hora

asked on

Tabs with left and right arrows - kindly any one help me faster please

This is the below code i m using show arrows for bootstrap tabs ..

i just need to show arrows not from beginning . when more tabs open lets assume 5 . show arrows i mean to say if more than 5 tabs open then will show right arrow becuase i want to navigate to right if have more than 5 or 6 then show left arrow to to navigate back to same tabs .

and if i don`t have tabs more than 5 then don`t show even arrows both .

Kindly any one can help faster please

var widthOfList = function(){
  var itemsWidth = 0;
  $('#tabs>li').each(function(){
    var itemWidth = $(this).outerWidth();
    itemsWidth+=itemWidth;
  });
  return itemsWidth;
}

var widthOfHidden = function(){
  return (($('#tabs').outerWidth())-widthOfList()-getLeftPosi())-scrollBarWidths;
};

var autocollapse = function() {
  var tabs = $('#tabs');
  
  if ((tabs.outerWidth()) < widthOfList()) {
    $('#leftArr').hide();
    $('#rightArr').show();
  }  
};

$(document).ready(function() {
  
  	autocollapse(); // when document first loads

	$(window).on('resize', autocollapse); // when window is resized
  
    $('#rightArr').click(function() {
     $('#tabs').css('position','absolute');
     $('#tabs').animate({right:"+5px"},'slow',function(){
        $('#rightArr').hide();
        $('#leftArr').show();
        autocollapse();
      });  	
	});
  
    $('#leftArr').click(function() {
      $('#tabs').animate({left:'-=0'},'slow',function(){
         $('#tabs').removeAttr('style');
         $('#leftArr').hide();
         autocollapse();
      });  	
	});
});

Open in new window


<div class="container-fluid">
	<div class="row">
      <a href="#" id="leftArr" class="arrow">
        <i class="glyphicon glyphicon-chevron-left"></i>
      </a>
      <a href="#" id="rightArr" class="arrow">
        <i class="glyphicon glyphicon-chevron-right"></i>
      </a>
      <ul class="nav nav-tabs" id="tabs">
          <li><a href="#">Tab0</a></li>
          <li><a href="#">Tab1</a></li>
          <li><a href="#">Tab2</a></li>
          <li><a href="#">Tab3</a></li>
          <li><a href="#">Tab4</a></li>
          <li><a href="#">Tab5</a></li>	  
          <li><a href="#">Tab6</a></li>
          <li><a href="#">Tab7</a></li>
          <li><a href="#">Tab8</a></li>
          <li><a href="#">Tab9</a></li>
          <li><a href="#">Tab10</a></li>
          <li><a href="#">Tab11</a></li>
          <li><a href="#">Tab12</a></li>
          <li><a href="#">Tab13</a></li>
          <li><a href="#">Tab14</a></li>	
          <li><a href="#">Tab15</a></li>
          <li><a href="#">Tab16</a></li>
          <li><a href="#">Tab17</a></li>
          <li><a href="#">Tab18</a></li>
          <li><a href="#">Tab19</a></li>
          <li><a href="#">Tab20</a></li>
          <li><a href="#">Tab21</a></li>
      </ul>
    </div>
</div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sastry_hora
sastry_hora

ASKER

Thanks for your response at least you responded my question . i made fiddle here the link http://jsfiddle.net/m0xck7k9/1/ 

now you see right now by default . i want this will be visible when i have more than 25 tabs .. i m adding tabs using jquery dynamically lets say if i set a value 25 then show right arrow to see more tabs . just wanted to show arrow when tabs increase more than i specified number.  Hope you understand what i mean to say please let me know
???
???
???
I looked at your  fiddle code works, and I clicked on the Right arrow, and NOTHING HAPPENED, nothing, no movement of tabs, not change in any page elements that I could see.
Shouldn't you get the tab movement working, before you even try and do other peripheral stuff like count the tabs (or get width) and show or hide any arrows? ?

I do not understand why you have the function -
   autocollapse()
all over the place, you do NOT need that functioning except maybe in the page start event.

Next, I do not think that you understand how to do <div> (or <ul> in this) movement inside another container <div> like   <div class="row">
I did not see any CSS class definition for class="row" , is this some sort of Bootstrap CSS?

anyway, I can try to greatly change the fiddle code
yes that is bootstrap css row class i mean .. and just click on right side arrow button i mean arrow right corner button you will hyper link there. i took this code from google needs to tweek a bit work as expected with your help. please
OK I altered the fiddle at
http://jsfiddle.net/m0xck7k9/3/

and now  more or less seems to work in firefox and chrome,  JUST to move the Tabs to the right and left, I did this but I do not have time to do the full development for this, as your tabs are NOT all the same width, and it can get really picky code work (much time) to try and get all tab elements width at different positions, and recalculate the relative movement positions.

Please notice how I took the arrows OUT of the tab <div> placement altogether, AND how I set the css for .row to position:relative;

AND the visible Borders I added are for DEvelopment ONLY, as I need to see where the boundries of elements to make pixel adjustments.
this is not so responsive, as I set the .row { width:

to a fixed amount to show about 5 tabs