これは私にとってはうまくいくようです。min-height
の代わりに使用height
.specs {
width: 930px;
/*min-height: 100px; CHECK UPDATE */
border: none;
color: #ffffff;
font-weight: normal;
display: none;
}
更新:http://jsfiddle.net/LLQyV/1/で実際の動作を確認してください
これを試して。CSSからmin-heightを削除します。
HTMLで、このようにtoggleContainerとして分類されたdivで各仕様を囲みます(私はあなたの一般的なカテゴリを複製し、それぞれにさまざまな仕様を追加しました)。
<!-- General -->
<div class="toggleContainer">
<div class="spec-cat">
<div class="spec-cat-content" id="general"><a href="#general">General</a>
<span class="spec-cat-desc"></span></div>
</div>
<div class="specs" id="sec1">
<ul>
<li>Manufactured by HTC</li>
<li>Also known as HTC Ville and HTC Z520e</li>
<li>Released in March 2012</li>
<li>£429 (GBP); $399 (USD)</li>
<li>Manufactured by HTC</li>
<li>Also known as HTC Ville and HTC Z520e</li>
<li>Released in March 2012</li>
<li>£429 (GBP); $399 (USD)</li>
</ul>
</div>
</div>
<!-- General -->
<div class="toggleContainer">
<div class="spec-cat">
<div class="spec-cat-content" id="general"><a href="#general">General</a>
<span class="spec-cat-desc"></span></div>
</div>
<div class="specs" id="sec1">
<ul>
<li>£429 (GBP); $399 (USD)</li>
</ul>
</div>
</div>
<!-- General -->
<div class="toggleContainer">
<div class="spec-cat">
<div class="spec-cat-content" id="general"><a href="#general">General</a>
<span class="spec-cat-desc"></span></div>
</div>
<div class="specs" id="sec1">
<ul>
<li>Manufactured by HTC</li>
<li>Also known as HTC Ville and HTC Z520e</li>
</ul>
</div>
</div>
次に、JSファイルでこれを実行します(すべてのonclick ='toggle'呼び出しをこれに結合しました)
$(function() {
$(".toggleContainer").each(function() {
//store the .specs height to an unchanging attribute
$(this).find(".specs").attr("specHeight", $(this).find(".specs").height());
//when the cat is clicked, expand or collapse the spec
$(this).find(".spec-cat-content").click(function(e) {
e.preventDefault();
//find spec for current toggleContainer that contains this category toggle button
var spec = $(this).parent().parent().find(".specs");
//check to see if the spec is displayed.
if ($(spec).css("display") == "none") {
//if it isn't then animate to specHeight attr and display block $(spec).height(0);
$(spec).css("display","block");
var newHeight=$(spec).attr("specHeight");
if(newHeight<100)
newHeight=100;
$(spec).animate({height:newHeight},400);
}
else {
//if it is, then animate to 0 height, and display:none
$(spec).animate({height:0},400,function(){$(spec).css("display","none");});
}
});
});
});