阅读 更多 关于 it. To enable history support for Tabs I use my History/Remote plugin.
First tab is active by default:
$('#container').tabs();
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Second tab is active:
$('#container').tabs(2);
Two alternative ways to specify the active tab will overrule this argument. First a li element (representing one single tab) belonging to the selected tab class, e.g. set the selected tab class (default: "tabs-selected", see option selectedClass) for one of the unordered li elements in the HTML source. In addition if a fragment identifier/hash in the URL of the page refers to the id of a tab container of a tab interface the corresponding tab will be activated and both the initial argument as well as an eventually declared class attribute will be overruled.
Use a slide effect to switch tabs.
You can optionally specify the speed for the animation with the option fxSpeed: value
.
The value is either a string of one of the predefined speeds in jQuery (slow
,
normal
, fast
) or an integer value specifying the duration for the animation
in milliseconds. If omitted it defaults to normal
.
$('#container').tabs({ fxSlide: true });
Use a fade effect to switch tabs.
You can optionally specify the speed for the animation with the option fxSpeed: value
.
The value is either a string of one of the predefined speeds in jQuery (slow
,
normal
, fast
) or an integer value specifying the duration for the animation
in milliseconds. If omitted it defaults to normal
.
$('#container').tabs({ fxFade: true, fxSpeed: 'fast' });
Use a combined slide and fade effect to switch tabs:
$('#container').tabs({ fxSlide: true, fxFade: true, fxSpeed: 'fast' });
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Define callback functions that are invoked at different points in time during the tab switch process.
These functions are invoked with three arguments: the first one being the clicked tab (the
a
element), the second one being the div
element that holds the content of
the clicked tab and the third one being the div
element belonging to the tab that gets hidden.
If the onClick callback returns false, the tab switch is canceled. This is especially useful if switching
tabs requires form validation before for example.
$('#container').tabs({
fxFade: true,
fxSpeed: 'fast',
onClick: function() {
alert('onClick');
},
onHide: function() {
alert('onHide');
},
onShow: function() {
alert('onShow');
}
});
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Adjust height of all tabs to the largest:
$('#container').tabs({ fxAutoHeight: true });
Define your own custom animation:
$('#container').tabs({ fxShow: { height: 'show', opacity: 'show' } });
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
If some HTML structure is required that differs from the default one, attach the classes
tabs-nav
to the unordered list, respectively tabs-container
to each container
and let the plugin automatically find the required elements by class.
$('#container').enableTab(3); // enables third tab
$('#container').triggerTab(3); // triggers third tab
$('#container').disableTab(3); // disables third tab
One or more tabs can also be disabled immediatly by simply setting the disabling class for the li element
representing that particular tab or by using the disabled
option.
<li class="tabs-disabled">…</li>
$('#container').tabs({ disabled: [2, 3] });
span
element inside a tab's anchor element.
activeTab
to retrieve currently selected tab. Usage: var index = $('#container').activeTab(); // => 1
spinner
, which lets you specify the text/image to be shown in a tab while loading remote content. Pass an empty string to entirely disable this behavior. Fixed bug, that allowed the onClick handler to be fired even for disabled and already selected tabs.
remote: true
disabled: [2, 3]
immediatly, else via $(…).disableTab(3);
. Enabling: $(…)enableTab(3);
.
A disabled tab is greyed out (using a configurable CSS class,
option disabledClass
) and isn't clickable.
bookmarkable
, extended callback system: onClick
, onHide
,
onShow
(onShow
replaces former callback
option)
fxAutoHeight
option to take window and text resizing into account (was
fxAutoheight
)