Bootstrap: Collapse other sections when one is expanded

后端 未结 11 830
一向
一向 2020-11-27 06:28

I am making a Rails app, and am trying to achieve a particular functionality relating to Twitter\'s Bootstrap collapse. Bear with me as I explain it.

I currently hav

11条回答
  •  眼角桃花
    2020-11-27 06:59

    Using data-parent, first solution is to stick to the example selector architecture

    keys
    attrs
    edit

    Demo (jsfiddle)

    Second solution is to bind on the events and hide the other collapsible elements yourself.

    var $myGroup = $('#myGroup');
    $myGroup.on('show.bs.collapse','.collapse', function() {
        $myGroup.find('.collapse.in').collapse('hide');
    });
    

    Demo (jsfiddle)

    PS: the strange effect in the demos is caused by the min-height set for the example, just ignore that.


    Edit: changed the JS event from show to show.bs.collapse as specified in Bootstrap documentation.

提交回复
热议问题