Bootstrap 3 collapse accordion: collapse all works but then cannot expand all while maintaining data-parent

后端 未结 4 458
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 00:52

I\'m using Bootstrap 3 and trying to setup the following accordion/collapse structure:

  1. Onload: Each accordion panel in a group is fully collapsed and functi

4条回答
  •  日久生厌
    2020-12-05 01:44

    To keep the accordion nature intact when wanting to also use 'hide' and 'show' functions like .collapse( 'hide' ), you must initialize the collapsible panels with the parent property set in the object with toggle: false before making any calls to 'hide' or 'show'

    // initialize collapsible panels
    $('#accordion .collapse').collapse({
      toggle: false,
      parent: '#accordion'
    });
    
    // show panel one (will collapse others in accordion)
    $( '#collapseOne' ).collapse( 'show' );
    
    // show panel two (will collapse others in accordion)
    $( '#collapseTwo' ).collapse( 'show' );
    
    // hide panel two (will not collapse/expand others in accordion)
    $( '#collapseTwo' ).collapse( 'hide' );
    

提交回复
热议问题