如何在所有菜单关闭的情况下加载我的手风琴?

发布于 2025-01-08 03:50:23 字数 440 浏览 3 评论 0原文

我试图按照这里的示例

http://twitter.github.com/bootstrap/ javascript.html#collapse

我在这里放置了一个模型

http://jsfiddle.net/gqe7g/

加载行为是 奇怪的。它显示 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

http://jsfiddle.net/gqe7g/

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

他是夢罘是命 2025-01-15 03:50:24

来自文档:

如果您希望它默认打开,请添加附加类。

换句话说,省略“in”,它将默认关闭。 http://jsfiddle.net/JBRh7/

From the doc:

If you'd like it to default open, add the additional class in.

In other words, leave out the "in" and it will default to close. http://jsfiddle.net/JBRh7/

月棠 2025-01-15 03:50:24

如果要在页面加载时关闭所有折叠:

collapse in 类中将其替换为 collapse 类。

id="collapseOne" class="panel-collapse collapse **in**" role="tabpanel" aria-labelledby="headingOne">

更新为:

id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">

If you want to close all collapsed on page load:

In class collapse in replace it to class collapse.

id="collapseOne" class="panel-collapse collapse **in**" role="tabpanel" aria-labelledby="headingOne">

Update to:

id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
归属感 2025-01-15 03:50:24

替换

$(".collapse").collapse();
$('#accordion').collapse({hide: true})

为:

$('#collapseOne').collapse("hide");

应该可以解决问题。我认为第一个默认情况下是打开的,而这一行将其关闭。

Replacing

$(".collapse").collapse();
$('#accordion').collapse({hide: true})

with:

$('#collapseOne').collapse("hide");

should do the trick. I think the first one is toggled on by default and this one line switches it off.

是你 2025-01-15 03:50:24

更改

class="accordion-body collapse in"

class="accordion-body collapse"

在您的 collapseOne DIV

Change

class="accordion-body collapse in"

TO

class="accordion-body collapse"

On your collapseOne DIV

冷清清 2025-01-15 03:50:24

如果您想要 最初,您可以使用预先存在的 定义,不需要javascript。

collapsed 类添加到锚点或句柄,该锚点或句柄将成为用户 它们打开/关闭。另外,从折叠容器中删除 in 类。

Bootstrap 还提供了一些可选规范,可以通过添加 data-parent=""data-toggle=""

  • data-parent 来传递> 接受一个选择器并指定作为数据父级同级的所有可折叠元素将一致切换。
  • data-toggle 接受布尔值 truefalse 并在可折叠元素上设置调用。

示例场景:

将加载折叠的

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse">
            <div class="accordion-inner">
                Details

将加载展开的

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body">
            <div class="accordion-inner">
                Details

将加载展开的

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse in">
            <div class="accordion-inner">
                Details

在第三个示例中,手风琴将默认展开,无论事实上,指定 collapsed 类是因为容器上的 in 类将获得更多权重。


如果您确实想通过 Javascript 触发折叠面板,您只需调用方法 collapse() 以及针对可折叠元素的相应 id 或类选择器。

collapse() 还接受与添加到标记中相同的选项。 data-parentdata-toggle

If you want the to initially you can do so with pre-existing definitions, javascript is unnecessary.

Adding the class collapsed to the anchor or handle which will be the click target for users to them open/closed. Also, remove the in class from the collapsing container.

Bootstrap also provides a couple of optional specifications which can be passed by adding data-parent="" and data-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 boolean true or false and sets invocation on the collapsible element.

Example Scenarios:

Will load collapsed

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse">
            <div class="accordion-inner">
                Details

Will load expanded

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body">
            <div class="accordion-inner">
                Details

Will load expanded

<div class="accordion" id="accordion2">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                Title
            </a>
        </div>
        <div id="collapseOne" class="accordion-body collapse in">
            <div class="accordion-inner">
                Details

In the 3rd example, the accordion will default to being expanded regardless of the fact that the collapsed class is specified because the in 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 and data-toggle

碍人泪离人颜 2025-01-15 03:50:24

您缺少 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 have class="accordion-body collapse"

http://jsfiddle.net/fcJJT/

甜嗑 2025-01-15 03:50:24

您可以将选项 toggle: false 传递给折叠语句,以使手风琴的所有元素在加载时隐藏,如下所示:

$('.collapse').collapse({
    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:

$('.collapse').collapse({
    toggle: false
});

Demo: http://jsfiddle.net/gqe7g/9/

溺孤伤于心 2025-01-15 03:50:24

这就是我用于手风琴的东西。它开始时完全关闭。
你想要

 active: false;//this does the trick

完整的:

<div id="accordian_div">
    <h1>first</h1>
        <div>
            put something here
        </div>
    <h1>second</h1>
        <div>
            put something here
        </div>
    <h1>third</h1>
        <div>
            put something here
        </div>
</div>

<script type="text/javascript">
     $(document).ready(function() {
        $("#accordian_div").accordion({
            collapsible: true,
            active: false,
            clearStyle: true
        });
      });
</script>

不熟悉bottstrap,但这似乎比你必须处理的所有课程都要干净一些,并且工作顺利。

this is what i use for my accordian. it starts off fully closed.
you want

 active: false;//this does the trick

full:

<div id="accordian_div">
    <h1>first</h1>
        <div>
            put something here
        </div>
    <h1>second</h1>
        <div>
            put something here
        </div>
    <h1>third</h1>
        <div>
            put something here
        </div>
</div>

<script type="text/javascript">
     $(document).ready(function() {
        $("#accordian_div").accordion({
            collapsible: true,
            active: false,
            clearStyle: true
        });
      });
</script>

Not familiar with bottstrap but this seems a bit cleaner than all the classes you have to deal with and works smoothly.

旧人九事 2025-01-15 03:50:24

只需从“collapseOne”中的 .panel-collapse 中删除 .in 类即可。 (引导程序 v3.3.7)

Just remove the .in class from .panel-collapse in "collapseOne". (Bootstrap v3.3.7)

很糊涂小朋友 2025-01-15 03:50:24

使用Bootstrap提供的hide方法,

$('.collapse').collapse('hide')

Demo在http://thefanciful.com。我的信息在加载时隐藏,并在按下按钮时激活。 :)

Use the hide method that Bootstrap provides,

$('.collapse').collapse('hide')

Demo at http://thefanciful.com. My information is hidden on load, and activates when the button is pushed. :)

满身野味 2025-01-15 03:50:24

使用 jQuery,这对我来说很有用,在页面加载时所有容器折叠

添加 {active: false} 并且必须具有可折叠 当然启用

  $(function () {
      $("#accordion").accordion({ collapsible: true, active: false });
      $(".selector").accordion();
  });

Using jQuery, This worked for me having ALL containers collapsed at page load

Adding {active: false} and must have collapsible enabled of course

  $(function () {
      $("#accordion").accordion({ collapsible: true, active: false });
      $(".selector").accordion();
  });
述情 2025-01-15 03:50:24
<script type="text/javascript">  

    jQuery(document).ready(function ($) {

       $('#collapseOne').collapse("hide");
    });      

</script>
<script type="text/javascript">  

    jQuery(document).ready(function ($) {

       $('#collapseOne').collapse("hide");
    });      

</script>
硬不硬你别怂 2025-01-15 03:50:24

我知道这是一个古老的讨论,但这里还有两个有效的解决方案:

1)添加

一个 aria-expanded="true" 类
在此链接内:

<a data-toggle="collapse" data-parent="#accordion"...></a>

2)如果您使用面板(如下所示),

<div id="collapse1" class="panel-collapse out collapse in" style="height: auto;">

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:

<a data-toggle="collapse" data-parent="#accordion"...></a>

2) In case you're using panels (like below)

<div id="collapse1" class="panel-collapse out collapse in" style="height: auto;">

changing collapse in to collapse out will also do the trick

战皆罪 2025-01-15 03:50:24

我知道这可能是一种有点 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文