"Responsive Accordion to Tabs"
Bootstrap 3.3.0 Snippet by farmpara

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <h2>Responsive Accordion to Tabs - FARMPARA</h2> <ul id="nav"> <li><a href="#">Item 1</a> <section> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pellentesque lorem, id suscipit dolor rutrum id. Morbi facilisis porta volutpat. Fusce adipiscing, mauris quis congue tincidunt, sapien purus suscipit odio, quis dictum odio tortor in sem. Ut sit amet libero nec orci mattis fringilla. Praesent eu ipsum in sapien tincidunt molestie sed ut magna. Nam accumsan dui at orci rhoncus pharetra tincidunt elit ullamcorper. Sed ac mauris ipsum. Nullam imperdiet sapien id purus pretium id aliquam mi ullamcorper.</p> </section> </li> <li><a href="#">Item 2</a> <section> <p>Ut laoreet augue et neque pretium non sagittis nibh pulvinar. Etiam ornare tincidunt orci quis ultrices. Pellentesque ac sapien ac purus gravida ullamcorper. Duis rhoncus sodales lacus, vitae adipiscing tellus pharetra sed. Praesent bibendum lacus quis metus condimentum ac accumsan orci vulputate. Aenean fringilla massa vitae metus facilisis congue. Morbi placerat eros ac sapien semper pulvinar. Vestibulum facilisis, ligula a molestie venenatis, metus justo ullamcorper ipsum, congue aliquet dolor tortor eu neque. Sed imperdiet, nibh ut vestibulum tempor, nibh dui volutpat lacus, vel gravida magna justo sit amet quam. Quisque tincidunt ligula at nisl imperdiet sagittis. Morbi rutrum tempor arcu, non ultrices sem semper a. Aliquam quis sem mi.</p> </section> </li> <li><a href="#">Item 3</a> <section> <p>Donec mattis mauris gravida metus laoreet non rutrum sem viverra. Aenean nibh libero, viverra vel vestibulum in, porttitor ut sapien. Phasellus tempor lorem id justo ornare tincidunt. Nulla faucibus, purus eu placerat fermentum, velit mi iaculis nunc, bibendum tincidunt ipsum justo eu mauris. Nulla facilisi. Vestibulum vel lectus ac purus tempus suscipit nec sit amet eros. Nullam fringilla, enim eu lobortis dapibus, quam magna tincidunt nibh, sit amet imperdiet dolor justo congue turpis.</p> </section> </li> <li><a href="#">Item 4</a> <section> <p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus dui urna, mollis vel suscipit in, pharetra at ligula. Pellentesque a est vel est fermentum pellentesque sed sit amet dolor. Nunc in dapibus nibh. Aliquam erat volutpat. Phasellus vel dui sed nibh iaculis convallis id sit amet urna. Proin nec tellus quis justo consequat accumsan. Vivamus turpis enim, auctor eget placerat eget, aliquam ut sapien.</p> </section> </li> </ul>
@import "compass/css3"; #nav { margin: 24px auto; border-top: 1px solid #999; border-right: 1px solid #999; border-left: 1px solid #999; width: 95%; } ul#nav { padding: 0; } #nav li { list-style: none; } #nav li a { display: block; padding: 10px 15px; background: #ccc; border-top: 1px solid #eee; border-bottom: 1px solid #999; text-decoration: none; color: #000; } #nav li a:hover, #nav li a.active { background: #B3B3B3; color: #F2F2F2; } #nav section { display: none; /* I NEED TO FIX THIS */ float: left; background: #B3B3B3; overflow: hidden; padding: 1% 3% 0 3%; } .no-js #nav section { display: block; /* I NEED TO FIX THIS */ } #nav li ul li a { padding: 10px 25px; border-bottom: 1px dotted #ccc; } @media only screen and (min-width: 30em) { #nav {width: 80%; position: relative; border: none; } #nav li { display: inline; } #nav li a {display: inline-block; } #nav section { padding: 1%; position: absolute; top: 42px; left: 0; } }
$(document).ready(function () { $('#nav').children('li').first().children('a').addClass('active') .next().addClass('is-open').show(); $('#nav').on('click', 'li > a', function() { if (!$(this).hasClass('active')) { $('#nav .is-open').removeClass('is-open').hide(); $(this).next().toggleClass('is-open').toggle(); $('#nav').find('.active').removeClass('active'); $(this).addClass('active'); } else { $('#nav .is-open').removeClass('is-open').hide(); $(this).removeClass('active'); } }); });

Related: See More


Questions / Comments:

Hi,

Item 1 default is open when i click on second time is close can make it open instead of closed?

Thanks,

YC () - 7 years ago - Reply 0