Collapse tabs

function autoCollapseTabs() { var $tabs = $('#tabs-subpages'), $last_tab = $('#last-tab'); var tabsHeight = $tabs.innerHeight(), threshold; switch ($window.width()) { default: threshold = 80; break; } if (tabsHeight >= threshold) { $last_tab.removeClass('bs-hidden'); while(tabsHeight > threshold) { var children = $tabs.children('li:not(:last-child)'); var count = children.size(); $(children[count-1]).prependTo('#extra-tabs'); tabsHeight = $tabs.innerHeight(); } } else { if ($('#extra-tabs').children('li').size() === 0) $last_tab.addClass('bs-hidden'); while(tabsHeight < threshold && ($('#extra-tabs').children('li').size()>0)) { var collapsed = $('#extra-tabs').children('li'); var count = collapsed.size(); $(collapsed[0]).insertBefore($tabs.children('li:last-child')); tabsHeight = $tabs.innerHeight(); } if (tabsHeight > threshold) { autoCollapseTabs(); } } }
Collapse (bootstrap) tabs into dropdown if they don't fit in screen

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.