如何在所有菜单关闭的情况下加载我的手风琴?
我试图按照这里的示例
http://twitter.github.com/bootstrap/ javascript.html#collapse
我在这里放置了一个模型
加载行为是 奇怪的。它显示 Menu1,然后折叠它,然后显示 Menu2 和 Menu3。我想把所有打开的东西都折叠起来。我尝试过以下操作但没有成功
$('#accordion').collapse({hide: true})
I'm trying to follow the example here
http://twitter.github.com/bootstrap/javascript.html#collapse
I have placed a mockup here
Loading behavior is strange. It shows Menu1 then collapses it then shows Menu2 and Menu3. I would like everything to open collapsed. I have tried the following without success
$('#accordion').collapse({hide: true})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
来自文档:
换句话说,省略“in”,它将默认关闭。 http://jsfiddle.net/JBRh7/
From the doc:
In other words, leave out the "in" and it will default to close. http://jsfiddle.net/JBRh7/
如果要在页面加载时关闭所有折叠:
在
collapse in
类中将其替换为collapse
类。更新为:
If you want to close all collapsed on page load:
In class
collapse in
replace it to classcollapse
.Update to:
替换
为:
应该可以解决问题。我认为第一个默认情况下是打开的,而这一行将其关闭。
Replacing
with:
should do the trick. I think the first one is toggled on by default and this one line switches it off.
更改
为
在您的 collapseOne DIV 上
Change
TO
On your collapseOne DIV
如果您想要手风琴到collapse 最初,您可以使用预先存在的 bootstrap 定义,不需要javascript。
将
collapsed
类添加到锚点或句柄,该锚点或句柄将成为用户切换 它们打开/关闭。另外,从折叠容器中删除in
类。Bootstrap 还提供了一些可选规范,可以通过添加
data-parent=""
和data-toggle=""
data-parent
来传递> 接受一个选择器并指定作为数据父级同级的所有可折叠元素将一致切换。data-toggle
接受布尔值true
或false
并在可折叠元素上设置调用。示例场景:
➤ 将加载折叠的
➤ 将加载展开的
➤ 将加载展开的
在第三个示例中,手风琴将默认展开,无论事实上,指定
collapsed
类是因为容器上的in
类将获得更多权重。如果您确实想通过 Javascript 触发折叠面板,您只需调用方法
collapse()
以及针对可折叠元素的相应 id 或类选择器。collapse()
还接受与添加到标记中相同的选项。data-parent
和data-toggle
If you want the accordion to collapse initially you can do so with pre-existing bootstrap definitions, javascript is unnecessary.
Adding the class
collapsed
to the anchor or handle which will be the click target for users to toggle them open/closed. Also, remove thein
class from the collapsing container.Bootstrap also provides a couple of optional specifications which can be passed by adding
data-parent=""
anddata-toggle=""
data-parent
accepts a selector and specifies that all collapsible elements which are siblings of the data-parent will be toggled in unison.data-toggle
accepts a booleantrue
orfalse
and sets invocation on the collapsible element.Example Scenarios:
➤ Will load collapsed
➤ Will load expanded
➤ Will load expanded
In the 3rd example, the accordion will default to being expanded regardless of the fact that the
collapsed
class is specified because thein
class on the container will receive more weight.If you do want to trigger the accordion via Javascript you only have to call the method
collapse()
along with the appropriate id or class selector which targets the collapsible element.collapse()
also accepts the same options as can be added to the markup.data-parent
anddata-toggle
您缺少 Menu2 和 Menu3 的折叠体 div 上的类“in”,
每个折叠体 div 都需要
class="accordion-body crash in"
。现在,其中一些只有class="accordion-body crash"
http://jsfiddle.net/fcJJT /
you're missing the class 'in' on accordion-body divs for Menu2 and Menu3
each of your accordion-body divs needs to have
class="accordion-body collapse in"
. Right now, a couple of them just haveclass="accordion-body collapse"
http://jsfiddle.net/fcJJT/
您可以将选项
toggle: false
传递给折叠语句,以使手风琴的所有元素在加载时隐藏,如下所示:演示:http://jsfiddle.net/gqe7g/9/
You can pass the option
toggle: false
to the collapse statement to have all elements of the accordion hidden on load, like so:Demo: http://jsfiddle.net/gqe7g/9/
这就是我用于手风琴的东西。它开始时完全关闭。
你想要
完整的:
不熟悉bottstrap,但这似乎比你必须处理的所有课程都要干净一些,并且工作顺利。
this is what i use for my accordian. it starts off fully closed.
you want
full:
Not familiar with bottstrap but this seems a bit cleaner than all the classes you have to deal with and works smoothly.
只需从“collapseOne”中的
.panel-collapse
中删除.in
类即可。 (引导程序 v3.3.7)Just remove the
.in
class from.panel-collapse
in "collapseOne". (Bootstrap v3.3.7)使用Bootstrap提供的hide方法,
Demo在http://thefanciful.com。我的信息在加载时隐藏,并在按下按钮时激活。 :)
Use the hide method that Bootstrap provides,
Demo at http://thefanciful.com. My information is hidden on load, and activates when the button is pushed. :)
使用 jQuery,这对我来说很有用,在页面加载时所有容器折叠
添加
{active: false}
并且必须具有可折叠 当然启用
Using jQuery, This worked for me having ALL containers collapsed at page load
Adding
{active: false}
and must havecollapsible
enabled of course我知道这是一个古老的讨论,但这里还有两个有效的解决方案:
1)添加
一个 aria-expanded="true" 类
在此链接内:
2)如果您使用面板(如下所示),
将
collapse in
更改为collapse out
也可以解决问题I know this is an old discussion, but here are two more solutions that worked:
1) Add
a class of
aria-expanded="true"
inside this link:
2) In case you're using panels (like below)
changing
collapse in
tocollapse out
will also do the trick我知道这可能是一种有点 hacky 的方式,但我添加了自定义 css:
.elementor-accordion-item:first-child {
显示:无;
}
然后复制列表中的第一项,这样做的好处是,如果页面或网站上有多个手风琴,则只需执行一次。
I know it may be a slightly hacky way but I added custom css:
.elementor-accordion-item:first-child {
display: none;
}
and then duplicated the first item on the list, the great thing with this is if you have multiple accordions on the page or site you only need to do this once.