Is it possible to have only one section in jQuery UI Accordion?

主宰稳场 提交于 2020-01-06 01:44:26

问题


I will like to organize the structure and the design of my web system, for this reason I decided for the accordion component of jQuery (which is working pretty good) because I don't want to disturb the user with unnecessary space, so the user can decide if he want to see or not this information.

My problem is that I just have one section inside this accordion (this section is a panel of components) and I can not collapse one section in the accordion (at least I don't know how). If I add another section then is possible, but I just need one.

Can somebody help me in this case?


回答1:


You should set collapsible to true to indicate that all the sections can be closed at once. Unless you specify this, when you only have one section you can't close it since one section should be active all the time by default.

Set active to false if you want the section to be collapsed initially

$("#accordion").accordion({
  active: false,
  collapsible: true
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


<div id="accordion">
  <h3>Section 1</h3>
  <div>
    <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio.</p>
  </div>
</div>


来源:https://stackoverflow.com/questions/34629246/is-it-possible-to-have-only-one-section-in-jquery-ui-accordion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!