- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想延长 Bootstrap accordion example包括指示列表项是否展开的上/下 V 形符号。我注意到折叠列表项会将 collapsed
类添加到 button
,在这种情况下,我想显示一个 chrevon-down
图标;否则,对于展开的按钮,我想显示 chevron-up
图标。
我已经尝试在这个片段中实现它:
$(document).ready(function(){
$("#accordion button").click(function(){
$("#accordion button .mdi").each(function(){
$(this).toggleClass('mdi-chevron-up', function(){
return $(this).parent().hasClass('collapsed');
});
$(this).toggleClass('mdi-chevron-down', function(){
return (!$(this).parent().hasClass('collapsed'));
});
});
});
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div id="accordion">
<div class="card border-bottom-0">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="mdi mdi-chevron-up float-right"></i>
Pipeline Integrity Assessment and Design
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
Our services include the design and assessment of subsea pipelines for lateral and/or upheaval buckling, arctic pipelines subject to ice gouging, stamukha loadings and/or thaw settlements, and pipelines crossing active faults, as well as more routine design and assessment.
</div>
</div>
</div>
<div class="card border-bottom-0">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="mdi mdi-chevron-up float-right"></i>
Structural Reliability Assessment (SRA)
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<p>Ralf Peek has over 30 years of experience in the area of structural reliability assessment and the estimation and assessment of uncertainties affecting structural performance in order to ensure that safety margins are adequate to cover such uncertainties. His specific experience includes:
<ul>
<li>Reliability-based design of buried arctic subsea pipeline against loading by ice keels gouging the sea floor</li>
<li>SRA for pipelines subject to lateral buckling under thermal expansion</li>
<li>Operating pipelines subject to extreme conditions (for example, turbidity current loading)</li>
<li>Probabilistic response-based seismic loading assessment criteria</li>
<li>Nuclear containment structural reliability assessment</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
如果不按照 https://materialdesignicons.com/bootstrap 中所述下载字体,图标似乎不会显示。 .然而,我在“实际”应用程序中观察到的是,chrevrons 都指向同一方向并串联移动:
有人能指出这个实现有什么问题吗?
更新
仔细阅读文档 (http://api.jquery.com/toggleclass/),我注意到 .toggleClass()
的第二种形式需要一个 bool 值作为第二个输入参数,而不是一个返回 bool 值的函数。但是,使用此代码:
$(document).ready(function(){
$("#accordion button").click(function(){
$("#accordion button .mdi").each(function(){
$(this).toggleClass('mdi-chevron-up', $(this).parent().hasClass('collapsed'));
$(this).toggleClass('mdi-chevron-down', (!$(this).parent().hasClass('collapsed')));
});
});
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div id="accordion">
<div class="card border-bottom-0">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="mdi mdi-chevron-up float-right"></i>
Pipeline Integrity Assessment and Design
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
Our services include the design and assessment of subsea pipelines for lateral and/or upheaval buckling, arctic pipelines subject to ice gouging, stamukha loadings and/or thaw settlements, and pipelines crossing active faults, as well as more routine design and assessment.
</div>
</div>
</div>
<div class="card border-bottom-0">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="mdi mdi-chevron-down float-right"></i>
Structural Reliability Assessment (SRA)
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<p>Ralf Peek has over 30 years of experience in the area of structural reliability assessment and the estimation and assessment of uncertainties affecting structural performance in order to ensure that safety margins are adequate to cover such uncertainties. His specific experience includes:
<ul>
<li>Reliability-based design of buried arctic subsea pipeline against loading by ice keels gouging the sea floor</li>
<li>SRA for pipelines subject to lateral buckling under thermal expansion</li>
<li>Operating pipelines subject to extreme conditions (for example, turbidity current loading)</li>
<li>Probabilistic response-based seismic loading assessment criteria</li>
<li>Nuclear containment structural reliability assessment</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
最初我已将第二个图标更改为 chevron-down
,但我仍然观察到一些不良行为。最初显示如我所料:
但是,当我单击上面的列表项将其折叠时,下面的列表项也会反转其图标方向:
如何调试?
最佳答案
我会改变您使用 toggleClass
的方式。如果以空格分隔,则可以为匹配集中的每个元素切换一个以上的类名。查看文档:https://api.jquery.com/toggleclass/
为了实现所需的行为,我稍微更改了您的 JavaScript。现在,如果您单击带有 mdi-chevron-up
图标的打开面板的标题,该图标应更改为 mdi-chevron-down
。如果您单击带有 mdi-chevron-down
图标的已关闭面板的标题,它将更改为 mdi-chevron-up
,并且任何其他打开的面板都将关闭,并且更改为 mdi-chevron-down
。
希望这更符合您的要求。
function toggleChevron(e) {
$(e.target)
.prev('.card-header')
.find("i.mdi")
.toggleClass('mdi-chevron-down mdi-chevron-up');
}
$('#accordion').on('hidden.bs.collapse', toggleChevron);
$('#accordion').on('shown.bs.collapse', toggleChevron);
<link href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/2.4.85/css/materialdesignicons.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div id="accordion">
<div class="card border-bottom-0">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="mdi mdi-chevron-up float-right"></i>
Pipeline Integrity Assessment and Design
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
Our services include the design and assessment of subsea pipelines for lateral and/or upheaval buckling, arctic pipelines subject to ice gouging, stamukha loadings and/or thaw settlements, and pipelines crossing active faults, as well as more routine
design and assessment.
</div>
</div>
</div>
<div class="card border-bottom-0">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-light w-100 text-left collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="mdi mdi-chevron-down float-right"></i>
Structural Reliability Assessment (SRA)
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<p>Ralf Peek has over 30 years of experience in the area of structural reliability assessment and the estimation and assessment of uncertainties affecting structural performance in order to ensure that safety margins are adequate to cover such uncertainties.
His specific experience includes:
<ul>
<li>Reliability-based design of buried arctic subsea pipeline against loading by ice keels gouging the sea floor</li>
<li>SRA for pipelines subject to lateral buckling under thermal expansion</li>
<li>Operating pipelines subject to extreme conditions (for example, turbidity current loading)</li>
<li>Probabilistic response-based seismic loading assessment criteria</li>
<li>Nuclear containment structural reliability assessment</li>
</ul>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
关于javascript - 如何将展开/折叠图标的切换添加到 Bootstrap Accordion ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51125651/
我需要能够在我的 javascript 中折叠/折叠各种代码片段,有点像 C# 中的#region #endregion。我找不到执行此操作的方法,有什么帮助吗? 最佳答案 窗口菜单 -> 选择首选项
折叠 Accordion 时,我注意到在这段时间内没有显示边框。例如,当 Accordion 展开时,我们会在展开时看到边界。这也可以在折叠 Accordion 时完成吗? Accordion 折叠时
是否有任何插件或快捷方式可以隐藏 Sublime Text 2 中除代码部分之外的所有内容? 我需要一次折叠除部分之外的所有部分,而不是一次折叠一个部分。 谢谢~ 最佳答案 如果将鼠标悬停在行号上,您
在 Web 应用程序中,我有一个操作可能会以各种不同的方式失败,或者最终会成功。 在这种情况下,成功和失败由 SimpleResult 的子类表示(表示 HTTP 响应) 我使用 scalaz/上的
我的数据在这样的分组方案中分为三个连续的类别: 因此,整个“OCM”组被分解为名为“N/A”、“Financials”、“Industrials”等的子组,每个子组又被分解为进一步的子组。 我在 Ex
我正在尝试猫图书馆,但我很难在我应该导入和创建的东西之间导航。我的问题如下: sealed trait Checks case class CheckViolation(id: Long, msg:
有没有办法查看当前文件中打开的折叠位置? 我个人在打开折叠和移动时遇到问题,我无法找到折叠开始的线!也许有一个选项可以在数字旁边设置一个漂亮的折叠提示。也许是这样的: + 1 void myfunc(
我正在寻找一种按空白深度折叠纯文本的方法。我更喜欢 Notepad++ 解决方案,但如果它只能在另一个编辑器中完成,我可以处理。例如 Header is arbitrary text Child i
今天早上我遇到了优秀的 jstree jQuery UI 插件。一句话——太棒了!它易于使用,易于样式化,并且可以按照包装盒上的说明进行操作。我还没有弄清楚的一件事是 - 在我的应用程序中,我想确
我有以下XAML,其中堆叠了三个组框。这些组框的标题中是复选框。 我想要实现的是:当我选中/取消选中一个框时,我希望相应的groupbox能够以平滑的动画缓慢展开/折叠。 我正在Blend 4中尝试此
我知道如何使用 zO 打开光标下的所有折叠. 但是反向怎么做呢? 我想要类似 za 的东西确实如此,但也具有递归性。 附注。我知道有 zC ,但它会关闭与当前行相关的所有父级折叠,我想关闭子级。 最佳
我试图防止点击 About Us 时导航栏崩溃部分或 Projects以下代码中的部分。我已经尝试过event.stopPropagation()在这两个按钮上,但是当 jQuery 代码执行时,导航
我有一个DataGrid。它具有DataGrid.RowDetailsTemplate。当单击一个按钮时,它应该展开/折叠;我该怎么做?
我有一个 Storyboard动画,使用Opacity属性可以使控件淡出 View 。完成后,我想将控件的“可见性”设置为“折叠”。 我也想做相反的事情...将“可见性”设置为“可见”,然后使用 St
我将 SublimeText3 用于 C++ 和 Java。我想知道是否有办法折叠文件/类中的所有方法,然后将它们全部展开,而不管插入符号在哪里。或者有没有办法列出所有的功能/方法。 基本上我希望能够
如何在 YAML 中断开长字符串(如长 url 或文件名/路径),而不会将换行符变成空格? 示例输入: url: > https://example.com/?what=Lorem %20ip
给定: import shapeless._ case class F(x: Option[Int], y: Option[Int]) 我想帮忙写一个函数,f: def f(Option[Int]::
我想测试数组是否仅包含唯一元素,我的解决方案如下: function uniqueElements(a) { var r = true; while (a) { var [el, a]
我试图在单击“项目”按钮时使“javascript 项目”和“CGI 项目”滑动切换。但是,我不太明白为什么点击时只有CGI项目按钮切换,而javascript项目按钮保持不变? 我正在尝试使用 Jq
我有一组需要在 UI 中显示的项目,例如标题和其下的项目列表。 有一个父组件,我将在其中将此数据传递到如下所示的文件. 在此基础上显示了父子布局。 现在我需要根据标题的点击展开/折叠。 有一个可以附加
我是一名优秀的程序员,十分优秀!