Now the image above is an example of \" too many tabs \", It appea
There are multiple scenarios and cases to handle when showing tabs on single line.
div
around the ui-tab-header <ul>
and set the overflow as scroll
. This method works out of box as the browser handles the scrolling through the tab headers. But the default scrollbar provided by browser will look odd. So you need a customize/stylish scrollbar addon. ORExtended jQuery UI widget that offers scroll-able tab feature and does automatically handle responsive page size changes by showing navigation controls when required.
Features:
https://davidsekar.github.io/jQuery-UI-ScrollTabs
One plugin can be found here https://github.com/Casper1131/scroller it can be used for any undordered list.
I created yet another plugin for this. This time using Chrome style tab-resizing behaviour.
Initialize with
$( ".tabpanel" ).tabs().tabs('overflowResize');
Demo
GitHub
I have a different approach to this issue, as I think a scroll for the tabs is counter-intuitive. I created a plugin to do a dropdown when the tabs break to a second line.
https://github.com/jasonday/plusTabs
I've just made a very simple plugin for this. Basically you have to add one fixed length div and a moveable one to the tab navigator.
Plugin code:
(function ($) {
var settings = {
barheight: 38
}
$.fn.scrollabletab = function (options) {
var ops = $.extend(settings, options);
var ul = this.children('ul').first();
var ulHtmlOld = ul.html();
var tabBarWidth = $(this).width()-60;
ul.wrapInner('<div class="fixedContainer" style="height: ' + ops.barheight + 'px; width: ' + tabBarWidth + 'px; overflow: hidden; float: left;"><div class="moveableContainer" style="height: ' + ops.barheight + 'px; width: 5000px; position: relative; left: 0px;"></div></div>');
ul.append('<div style="width: 20px; float: left; height: ' + (ops.barheight - 2) + 'px; margin-left: 5px; margin-right: 0;"></div>');
var leftArrow = ul.children().last();
leftArrow.button({ icons: { secondary: "ui-icon ui-icon-carat-1-w" } });
leftArrow.children('.ui-icon-carat-1-w').first().css('left', '2px');
ul.append('<div style="width: 20px; float: left; height: ' + (ops.barheight - 2) + 'px; margin-left: 1px; margin-right: 0;"></div>');
var rightArrow = ul.children().last();
rightArrow.button({ icons: { secondary: "ui-icon ui-icon-carat-1-e" } });
rightArrow.children('.ui-icon-carat-1-e').first().css('left', '2px');
var moveable = ul.find('.moveableContainer').first();
leftArrow.click(function () {
var offset = tabBarWidth / 6;
var currentPosition = moveable.css('left').replace('px', '') / 1;
if (currentPosition + offset >= 0) {
moveable.stop().animate({ left: '0' }, 'slow');
}
else {
moveable.stop().animate({ left: currentPosition + offset + 'px' }, 'slow');
}
});
rightArrow.click(function () {
var offset = tabBarWidth / 6;
var currentPosition = moveable.css('left').replace('px', '') / 1;
var tabsRealWidth = 0;
ul.find('li').each(function (index, element) {
tabsRealWidth += $(element).width();
tabsRealWidth += ($(element).css('margin-right').replace('px', '') / 1);
});
tabsRealWidth *= -1;
if (currentPosition - tabBarWidth > tabsRealWidth) {
moveable.stop().animate({ left: currentPosition - offset + 'px' }, 'slow');
}
});
return this;
}; })(jQuery);
Check it out at http://jsfiddle.net/Bua2d/
Here is a plugin for that: http://jquery.aamirafridi.com/jst/