这似乎对我有用。使用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");});
}
});
});
});