I am using Bootstrap 3 accordion. After reading numerous posts on how to have independent behaviour on the contents, rather than keeping only one active by default, i use data-target and the id if the content instead of the default data-parent of the accordion id. The independent collapsing works fine, but now on collapse it scrolls to the top of the collapsible item. How can I disable this scrolling behaviour whilst keeping the collapsible in-dependancy?
Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.
In bootstrap context wise, accordion is basically a collapse button with a lot of smaller info in it. Bootstrap use card to make an accordion. on line 1, <div id="accordion" role="tablist"> , this is where the data-parent refers to. on line 2 <div class="card"> , we are using a card class, to show the card effect.
open accordian > at right side go to accordian seting > scrol down to Expand/Collapse Accordion Option On Page Load > choose Hide/close All Accordion.. thanks.
To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});
I think i know what causes the scrolling problem. If you are based on the example shown in getbootstrap.com, then you probably use anchors
<a data-toggle="collapse" data-content="#your-content" href="#your-content">...</a>
instead of anchors you can use spans
<span data-toggle="collapse" data-content="#your-content">...<span>
The href in the anchor is causing the scroll. I hope that helps
Just add class="your-header-class"
to the a header
element:
<a class="your-header-class" data-toggle="collapse" data-content="#your-content" href="#your-content">...</a>
and then add this:
$('.your-header-class').click(function(e) {
e.preventDefault();
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With