A simple, unobtrusive jQuery plugin for creating tabbed interfaces.
View the demo.
Matt Tabs tries to be as lightweight and unobtrusive as possible. As such, it doesn't require any additional HTML to be added into your markup to use for a tabs menu. Instead, when mtabs
is applied to an element it will use pre-existing markup for the tab text and then will build and insert all the HTML it needs.
The element used for the tab text, amongst other things, can be adjusted as described below. A full list of customisable options is also below.
Basic usage is simple:
$('.container').mtabs();
Converts all the children of .container
into tabs and inserts the tabs menu before them.
If you need to you can change the element used to generate the tab text for the menu.
This is done by supplying a valid jQuery selector to the tab_text_el
property when initialising Matt Tabs on an element.
$('.container').mtabs({
tab_text_el: '.heading'
});
The plugin will then find the first .heading
element within each child of .container
and use that instead.
Also, you can supply multiple selectors separated by a comma if, for example, .heading
wasn't available in each element. Something like this: .heading, .header
.
$('.container').mtabs({
onReady: function () {
// Do something here...
}
});
Called when .mtabs
has been fully instantiated.
$('.container').mtabs({
onTabSelect: function (idx) {
// Do something here...
}
});
onTabSelect
is fired every time a tab is selected. The function is passed the index of the selected tab as an argument.
Show particular tab in a given tab set. Index is 0-based.
For example, this will show the third tab in a tab set:
$('.container').mtabs('show', 2);
Destroys a current instance of .mtabs
, removing all data and addional HTML added by the plugin.
$('.container').mtabs('destroy');
tabs
.tabs-content
.active-tab
.h1-6
element within each element.tabs-menu
.ul
element.Here's a few of the features I had in mind for future releases of Matt Tabs:
http://example.com/?mtabs-1=3
. This would show tab number 3 in the first set of Matt Tabs on the page.