Responsive-Tabs is a very useful jQuery plugin that converts the tabs to accordion on mobile automatically through CSS breakpoint. By default, it transforms to an accordion below 768px, but you can modify this breakpoint in CSS as per your requirements.
Bower and NPM.$ bower install responsive-tabs
$ npm install responsive-tabs
1. Include the Javascript jquery.responsiveTabs.min.js at the bottom of the web page.
<script src="path/to/jquery.responsiveTabs.min.js"></script>
2. Include the CSS responsive-tabs.css in the header of the page.
<link rel="stylesheet" href="css/responsive-tabs.css">
3. Add the basic HTML to the page.
<div id="defaultTabs">
<ul>
<li><a href="#tab-1">Tab-1</a></li>
<li><a href="#tab-2">Tab-2</a></li>
<li><a href="#tab-3">Tab-3</a></li>
</ul>
<div id="tab-1">Tab content 1</div>
<div id="tab-2">Tab content 2</div>
<div id="tab-3">Tab content 3</div>
</div>
4. Initialize the plugin and we're ready to go.
$('#defaultTabs').responsiveTabs({
startCollapsed: 'accordion'
});
5. Include style.css for a basic tab/accordion theme
<link rel="stylesheet" href="path/to/style.css">
| Name | Default | Description |
|---|---|---|
| Collapsible | accordion |
|
| Start collapsed | false |
|
| Disabled tabs | [] |
|
| Active tab | null |
|
| Accordion Tab HTML element | '<div></div>' |
|
| Set hash | false |
|
| Rotate | false |
|
| Event | 'click' |
|
| Animation | default |
|
| Animation Queue | false |
|
| Animation Duration | 500 |
|
| Scroll to Accordion panel | false |
|
| Scroll To Accordion On Load | true |
|
| Scroll To Accordion Offset | false |
|
| Navigation container | '' |
|
This callback is called after a tab is clicked, regardless of whether it's disabled
Arguments
click: function(event, tab){},
This callback is called after a tab is selected
Arguments
activate: function(event, tab){},
This callback is called after a tab is deactivated
Arguments
deactivate: function(event, tab){},
This callback is called after the plugin has been loaded
Arguments
load: function(event, firstTab){},
This callback is called after the plugin switches from state (Tab view / Accordion view)
activateState: function(){}
<div id="defaultTabs">
<ul>
<li><a href="#tab-1">Tab-1</a></li>
<li><a href="#tab-2">Tab-2</a></li>
<li><a href="#tab-3">Tab-3</a></li>
</ul>
<div id="tab-1">Tab content 1</div>
<div id="tab-2">Tab content 2</div>
<div id="tab-3">Tab content 3</div>
</div>
$('#defaultTabs').responsiveTabs();
<div id="autoRotateTabs">
<ul>
<li><a href="#tab-4">Tab-1</a></li>
<li><a href="#tab-5">Tab-2</a></li>
<li><a href="#tab-6">Tab-3</a></li>
</ul>
<div id="tab-4">Tab content 1</div>
<div id="tab-5">Tab content 2</div>
<div id="tab-6">Tab content 3</div>
</div>
$('#autoRotateTabs').responsiveTabs({
rotate: true,
animation: 'slide'
});