gpt4 book ai didi

jquery - 带 Bootstrap 的两列 Accordion

转载 作者:行者123 更新时间:2023-12-01 01:33:26 24 4
gpt4 key购买 nike

我正在使用 Bootstrap,在设计中,我们有一个两列 Accordion 部分,一次只能有一个事件下拉状态。

单击下拉菜单后,我遇到了维护列的问题。左侧的元素在展开的部分下不断向右移动。

请参阅示例:Bootply

代码:

<div class="col-xs-11 col-sm-7">
<div class="panel-group" id="accordion">


<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne1">
TEST1
</a>
</h4>
</div>
<div id="collapseOne1" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>




<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo2">
TEST 2 </a>
</h4>
</div>
<div id="collapseTwo2" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTEST
</div>
</div>
</div>



<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree3">
TEST3 </a>
</h4>
</div>
<div id="collapseThree3" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTEST
</div>
</div>
</div>




<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseFour4">
TEST 4 </a>
</h4>
</div>
<div id="collapseFour4" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTEST
</div>
</div>
</div>






<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseFive5">
TEST 5 </a>
</h4>
</div>
<div id="collapseFive5" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTEST
</div>
</div>
</div>



<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseSix6">
TEST 6 </a>
</h4>
</div>
<div id="collapseSix6" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTEST
</div>
</div>
</div>

<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseSeven">
TEST 7 </a>
</h4>
</div>
<div id="collapseSeven" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTESTTEST
</div>
</div>
</div>


<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseEight">
TEST 8 </a>
</h4>
</div>
<div id="collapseEight" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTESTTEST
</div>
</div>
</div>




<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseNine">
TEST 9 </a>
</h4>
</div>
<div id="collapseNine" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTESTTEST
</div>
</div>
</div>




<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTen">
TEST 10 </a>
</h4>
</div>
<div id="collapseTen" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTESTTEST
</div>
</div>
</div>






<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseEleven">
TEST 11 </a>
</h4>
</div>
<div id="collapseEleven" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTESTTEST
</div>
</div>
</div>




<div class="panel panel-default col-sm-6">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTwelve">
TEST 12 </a>
</h4>
</div>
<div id="collapseTwelve" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>



</div>
</div>

感谢任何帮助!

最佳答案

不要在每个面板周围添加 col-sm-6,而是将两侧分组到各自的 div 中,并将“col-sm-6”添加到每个组

示例:http://www.bootply.com/vfbv3Cnn6v

<div class="col-xs-11 col-sm-7">
<div class="panel-group" id="accordion">

<!-- start panel left -->
<div class="panel-left col-sm-6">
<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_1">
TEST_1
</a>
</h4>
</div>
<div id="TEST_1" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_2">
TEST_2
</a>
</h4>
</div>
<div id="TEST_2" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_3">
TEST_3
</a>
</h4>
</div>
<div id="TEST_3" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_4">
TEST_4
</a>
</h4>
</div>
<div id="TEST_4" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_5">
TEST_5
</a>
</h4>
</div>
<div id="TEST_5" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_6">
TEST_6
</a>
</h4>
</div>
<div id="TEST_6" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->




</div>
<!-- end panel left -->


<!-- start panel right -->
<div class="panel-left col-sm-6">
<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_7">
TEST_7
</a>
</h4>
</div>
<div id="TEST_7" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_8">
TEST_8
</a>
</h4>
</div>
<div id="TEST_8" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_9">
TEST_9
</a>
</h4>
</div>
<div id="TEST_9" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_10">
TEST_10
</a>
</h4>
</div>
<div id="TEST_10" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_11">
TEST_11
</a>
</h4>
</div>
<div id="TEST_11" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->

<!-- start panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#TEST_12">
TEST_12
</a>
</h4>
</div>
<div id="TEST_12" class="panel-collapse collapse">
<div class="panel-body">
TESTTESTTESTTESTTEST
</div>
</div>
</div>
<!-- end panel -->




</div>
<!-- end panel right -->




</div>
</div>

我还发现,当我有大量嵌套 div 时,添加注释来显示重要区域的打开和关闭位置会很方便。

所以为了让 Accordion 仍然尊重打开和关闭 Bootstrap 文档,有一个事件 show.bs.collapse 在显示面板时会被触发,所以使用它来隐藏哪个面板具有类in(这表示打开的面板)

$('#accordion').on('show.bs.collapse', function () {
$('#accordion .in').collapse('hide');
});

关于jquery - 带 Bootstrap 的两列 Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25633028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com