您好,我是新来的,我想知道是否有人可以提供帮助。我已经实施了bourbon.io的手风琴,但是我无法单击一次打开并崩溃。
它打开,但随后保持开放。
$('.js-accordion-trigger').bind('click', function(e){
jQuery(this).parent().find('.submenu').slideToggle('fast'); // apply the toggle to the ul
jQuery(this).parent().toggleClass('is-expanded');
e.preventDefault();
});
jsfiddle demo
请参阅下面是否想要的是
$('.js-accordion-trigger').on('click', function(e) {
$('ul.submenu').not($(this).parent().find('ul.submenu')).slideUp('fast');
$(this).parent().find('.submenu').toggleClass('is-expanded').slideToggle('fast');
e.preventDefault();
});
ul.submenu {
display: none;
}
.is-expanded {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="accordion">
<li>
<a href="javascript:void(0)" class="js-accordion-trigger">Accordion Item</a>
<ul class="submenu">
<li>
<a href="javascript:void(0)">Sub Item 1</a>
</li>
<li>
<a href="javascript:void(0)">Sub Item 2</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)" class="js-accordion-trigger">Another Item</a>
<ul class="submenu">
<li>
<a href="javascript:void(0)">Sub Item 1</a>
</li>
<li>
<a href="javascript:void(0)">Sub Item 2</a>
</li>
</ul>
</li>
</ul>