Monday, June 3, 2024
142
rated 0 times [  147] [ 5]  / answers: 1 / hits: 15621  / 12 Years ago, fri, february 15, 2013, 12:00:00

The goal is to switch from tabs to an accordion style collapse when the site is less than 676px wide. We are using Bootstrap.



We'll hide ul.nav-tabs and a.accordtion-toggle respectively with css. The tabs work here, but the a.accordion-toggle aren't working. Any ideas?



<ul class=nav nav-tabs id=myTab data-tabs=tabs>
<li class=active><a href=#panel1 data-toggle=tab>Panel 1</a></li>
<li class=active><a href=#panel2 data-toggle=tab>Panel 2</a></li>
</ul>

<a class=accordion-toggle data-toggle=collapse data-target=#panel>Panel 1</a>
<div class=tab-pane collapse id=panel1>
Panel 1 Content
</div>
<a class=accordion-toggle data-toggle=collapse data-target=#pane2>Panel 2</a>
<div class=tab-pane collapse id=panel2>
Panel 2 Content
</div>

<script>
jQuery(document).ready(function ($) {
if (document.documentElement.clientWidth < 767) {
$('#myTab a').click(function (e) {
e.preventDefault();
}

$(.collapse).collapse();
}
});
</script>

More From » twitter-bootstrap

 Answers
12

I tried a bit on this jsfiddle but it seems complicated to make both plugins work together.



It might be better opting for one of the plugin, using only the classes and JS of this plugin, and then implement your own triggers to complete the default behavior.






I think the accordion behavior of the collapse plugin needs the .accordion-group > .collapse.in structure to work properly - if you don't use your own JS.


[#80198] Thursday, February 14, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nora

Total Points: 248
Total Questions: 111
Total Answers: 97

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
;