Bourbon 手风琴单击时单击一次 expand/collapse
Bourbon accordion click once expand/collapse when clicked
您好,我是新来的,我想知道是否有人可以提供帮助。我已经实现了 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();
});
看看下面是不是你想要的
$('.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>
您好,我是新来的,我想知道是否有人可以提供帮助。我已经实现了 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();
});
看看下面是不是你想要的
$('.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>