我有一个手风琴菜单(下面的代码),在手风琴菜单下我有一个标签框。当手风琴菜单扩展时,我想让我的标签框位于扩展菜单下方,而不是扩展菜单覆盖我的标签框。因此,在计算打开的子项的数量后,我更改了标签框的 CSS 属性“top”的值。
<div id="accordion">
<h3>NOTEBOOKS</h3>
<div class="sub_items" style="padding-top:0px;padding-bottom:0px;">
<div onMouseOver="bgFadeIn(this)" onMouseOut="bgFadeOut(this)">
<a href="http://127.0.0.1/casecrown_final/index.php/notebooks/black-slim.html">
<span>BLACK SLIM</span></a>
</div>
<div onMouseOver="bgFadeIn(this)" onMouseOut="bgFadeOut(this)">
<a href="http://127.0.0.1/casecrown_final/index.php/notebooks/checkered-slim.html">
<span>CHECKERED SLIM</span></a>
</div>
</div>
<h3>Another item</h3>
<div class=sub_items" ......
.......
.....
</div>
jQuery(document).ready(function() {
var countTotalCategories = jQuery('#accordion > h3').size();
var defaultHeight = countTotalCategories * 30;
jQuery('#accordion> div').hide();
jQuery('#accordion> h3').click(function() {
jQuery(this).next('div').slideToggle(400)
.siblings('div:visible').slideUp(400);
countProducts = jQuery(this).next('div').children('div:visible').size();
var calculatedHeight= defaultHeight + 29 * countProducts;
jQuery('.mini-product-tags').css('top' , calculatedHeight + 'px');
});
现在,我怎么知道用户是否正在打开一个新菜单来扩展它......或者用户正在关闭菜单。我不知道如何确定用户是否正在关闭菜单,以便在关闭所有手风琴菜单时将标签框值设置为默认值。似乎我只是在单击事件之后才弄清楚,我不确定何时处理 jQuery 切换事件。