matthewhall / matt-tabs

A simple jQuery plugin for creating tabbed interfaces.
Do What The F*ck You Want To Public License
6 stars 4 forks source link

Matt Tabs

A simple, unobtrusive jQuery plugin for creating tabbed interfaces.

View the demo.

Build

Build

Usage

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

Basic usage is simple:

$('.container').mtabs();

Converts all the children of .container into tabs and inserts the tabs menu before them.

Adjusting the tab text element

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.

Callbacks

onReady

$('.container').mtabs({
    onReady: function () {
        // Do something here...
    }
});

Called when .mtabs has been fully instantiated.

onTabSelect

$('.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.

Methods

.mtabs('show', index)

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);

.mtabs('destroy')

Destroys a current instance of .mtabs, removing all data and addional HTML added by the plugin.

$('.container').mtabs('destroy');

Options

Requires

Browser Support

Forecast

Here's a few of the features I had in mind for future releases of Matt Tabs: