简体   繁体   English

修改 Twitter Bootstrap collapse 插件保持手风琴打开

[英]Modify Twitter Bootstrap collapse plugin to keep accordions open

I'm trying to modify the Bootstrap collapse plugin to allow me to specify whether clicking an accordion (to open) should automatically close the other items in the accordion (so more than one item in the accordion can be open at a time)我正在尝试修改 Bootstrap 折叠插件以允许我指定单击手风琴(打开)是否应自动关闭手风琴中的其他项目(因此手风琴中的多个项目可以一次打开)

I want to create a new data attribute on the accordion, something like data-collapse-type="auto|manual"我想在手风琴上创建一个新的数据属性,比如data-collapse-type="auto|manual"

The bootstrap jQuery plugins are a bit advanced for my skill level. bootstrap jQuery 插件对于我的技能水平来说有点高级。 The most relevant part of what I need to mess with seems to be on line 52, actives.collapse('hide') .我需要处理的最相关部分似乎在第 52 行actives.collapse('hide')上。 I don't want that to happen if 'data-collapse-type="manual"' is set (omitting the attribute or setting auto should keep the default behavior).如果设置了“data-collapse-type="manual"'(省略属性或设置auto应该保持默认行为),我不希望发生这种情况。

I've created a jsfiddle where I've been experiementing .我创建了一个我一直在试验的jsfiddle

Can anyone help get me on the right track with this?谁能帮助我走上正轨?

Actually, you don't need to modify any code .实际上,您不需要修改任何代码 Read the following statement closely from twitterbootstrap site从 twitterbootstrap 站点仔细阅读以下声明

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element.只需将 data-toggle="collapse" 和 data-target 添加到元素即可自动分配对可折叠元素的控制。 The data-target attribute accepts a css selector to apply the collapse to. data-target 属性接受一个 css 选择器来应用折叠。 Be sure to add the class collapse to the collapsible element.请务必将 class collapse 添加到可折叠元素中。 If you'd like it to default open, add the additional class in.如果您希望它默认打开,请在中添加额外的 class。

So instead of using data-parent='#idofAccordion' , use data-target='#idofCollapseItem' .因此,不要使用data-parent='#idofAccordion' ,而是使用data-target='#idofCollapseItem'

It should work perfectly.它应该工作得很好。

Here is the demo on plunker这是plunker 上的演示

I have forked and updated your fiddle.我已经分叉并更新了你的小提琴。

just go to.show function, I have written also the comments.只是go to.show function,我也写了评论。

http://jsfiddle.net/2Rnpz/ http://jsfiddle.net/2Rnpz/

since the question didn't refer to a specific version of Bootstrap, here's a bootstrap 4 solution: remove the data-parent="#accordion" from the tags with the data-toggle="collapse" attribute.由于问题没有涉及特定版本的 Bootstrap,这里有一个 bootstrap 4 解决方案:从具有data-toggle="collapse"属性的标签中删除data-parent="#accordion" It's the example taken from the Collapse documentation with the data-parent=#accordion" bit taken out.这是取自 Collapse 文档的示例,其中删除了data-parent=#accordion"位。

bootply: https://www.bootply.com/3wV4WbzBtT# bootply: https://www.bootply.com/3wV4WbzBtT#

The technique for having only one accordion open at a time(that is collapse the rest), is placing both data-parent="#accordion" data-target="#collapseOne" so it looks like this一次只打开一个手风琴的技术(即折叠其余的),是放置两个 data-parent="#accordion" data-target="#collapseOne" 所以它看起来像这样

<a class="accordion-toggle" data-toggle="collapse" href="#"
    data-parent="#accordion" data-target="#collapseOne">
  Item #1
</a>

You can look at it in plunker: http://plnkr.co/edit/56iXtA?p=preview您可以在 plunker 中查看它: http://plnkr.co/edit/56iXtA?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM