gpt4 book ai didi

javascript - Bootstrap Accordion 从面板标题 + 状态指示器切换

转载 作者:行者123 更新时间:2023-12-03 11:47:45 25 4
gpt4 key购买 nike

通过尝试不同的 CSS 和 jQuery 解决方案,我已经尝试让它工作 8 个小时了,我找到了很多解决方案,但这些解决方案都不能满足我的需求。

我需要面板标题作为激活“按钮”,这样打开不同的部分会更容易。

所有可用的方法均无效。他们要么不做任何事情,要么在 Accordion 的每个选项卡上激活某些类,但我只需要当前激活的选项卡上的状态更改。

下面有一个没有 jQuery 的 jsfiddle,但我想我已经用 fontawesome 图标上的 class="indicator"很好地完成了标记。

抱歉,如果这是一个简单的问题,而且我看起来很愚蠢,但我确实缺乏 JavaScript 经验。

HTML:

<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" data-target="#collapseOne">
<h4 class="panel-title">
Collapsible Group Item #1<i class="fa indicator fa-chevron-up"></i>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
First group.Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" data-target="#collapseTwo">
<h4 class="panel-title">
Collapsible Group Item #2<i class="fa indicator fa-chevron-down"></i>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" data-target="#collapseThree">
<h4 class="panel-title">
Collapsible Group Item #3<i class="fa indicator fa-chevron-down"></i>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div>

CSS:

.panel-default>.panel-heading{background-color: #f5f5f5;border-bottom: 1px solid #fff;}
.panel-default{border: none;}
.panel-group .panel{border-radius: 0;}
.panel{-webkit-box-shadow:none;box-shadow:none;border-left: 1px solid #f5f5f5;}
.panel-group .panel-heading+.panel-collapse>.panel-body{border-top: none;}
.panel-group .panel+.panel{margin-top: 0;}
.panel-title .fa{color:#87D37C;float: right;}
.panel-heading{border-radius: 0;cursor:pointer;}

_

http://jsfiddle.net/3tweewn1/

最佳答案

font-awesome css 文件没有链接到你的 fiddle 上,所以我添加了一个不同的 cdn 链接,并添加了代码来在实际的 fiddle 上显示 font-awesome 字体,以便你可以看到它的实际效果。 http://jsfiddle.net/Lnws5fop/1/
我不确定您是否真的想要在面板标题旁边添加 V 形符号,因此我添加了“向右拉”,您可以根据需要将其删除。

function toggleChevron(e) {
$(e.target)
.prev('.panel-heading')
.find("i.indicator")
.toggleClass('fa-chevron-down fa-chevron-up');
}
$('#accordion').on('hidden.bs.collapse', toggleChevron);
$('#accordion').on('shown.bs.collapse', toggleChevron);

关于javascript - Bootstrap Accordion 从面板标题 + 状态指示器切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25977088/

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