アコーディオンメニュー(以下のコード)を取得し、アコーディオンメニューの下にタグボックスがあります。アコーディオンメニューが拡張されるとき、拡張メニューがタグボックスを覆うのではなく、タグボックスを拡張メニューの下に配置したいと思います。そのため、開いているサブアイテムの数を数えた後、タグボックスの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トグルイベントがいつ処理されているのかわからないことがわかったようです。