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

时间:2016-10-28 11:04:19

标签: javascript jquery accordion

这就是我使用的:JsFiddle

我希望默认关闭所有菜单。

提前致谢!

PS:我对JavaScript一无所知,所以如果你用小提琴来说明你的答案会有所帮助。

$('.info').find('.accordion-toggle').click(function () {
    //Expand or collapse this panel
    $(this).toggleClass("open").next().slideToggle('fast');
    //Hide the other panels
    $(".accordion-toggle").not($(this)).removeClass("open");
    $(".accordion-content").not($(this).next()).slideUp('fast');
});

2 个答案:

答案 0 :(得分:4)

删除"打开"和"默认"

<div class='info'>
     <h1 class='accordion-toggle'>Header 1 </h1>

    <div class='accordion-content'>Content 1...</div>
     <h1 class='accordion-toggle'>Header 2 </h1>

    <div class='accordion-content'>Content 2...</div>
     <h1 class='accordion-toggle'>Header 3 </h1>

    <div class='accordion-content'>Content 3...</div>
</div>

&#34;开&#34; class将标题样式设置为打开,&#34;默认&#34;将内容设置为在用户交互之前默认显示的内容

答案 1 :(得分:1)

查看更新后的JsFiddle

<div class='info'>
     <h1 class='accordion-toggle (remove this class ->)open'>Header 1 </h1>

    <div class='accordion-content (remove this class ->)default'>Content 1...</div>
     <h1 class='accordion-toggle'>Header 2 </h1>

    <div class='accordion-content'>Content 2...</div>
     <h1 class='accordion-toggle'>Header 3 </h1>

    <div class='accordion-content'>Content 3...</div>
</div>

不需要JS更改只需要删除第一个H1标记中的open类,而默认类就是它下面的div。