Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap accordion scrolling behaviour on collapse

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?

like image 658
Xavi3R Elvis Avatar asked Dec 10 '13 08:12

Xavi3R Elvis


People also ask

How do you collapse the accordion bootstrap?

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.

What is difference between collapse and accordion?

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.

How do you close an accordion when another opens?

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.

How do you collapse an accordion by default?

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});


2 Answers

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

like image 162
Apostolis P. Avatar answered Sep 23 '22 21:09

Apostolis P.


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();
})
like image 25
Primoz Rome Avatar answered Sep 24 '22 21:09

Primoz Rome