我有一個列表項修改代碼的價值。 這裏是結果:http://jsfiddle.net/CtGmH/1/
CSS
#table {
width: 100%;
}
#table ul {
height: 30px;
background: green;
list-style-type: none;
padding: 0;
margin: 10px;
}
#table ul.odd {
background: red;
}
table li{position: relative; }
HTML
<div id="table">
<ul class="odd"><li>A</li></ul>
<ul><li>B</li></ul>
<ul class="odd"><li>C</li></ul>
<ul><li>E</li></ul>
</div>
<button onclick="window.show()">Show</button>
<button onclick="window.hide()">Hide</button>
JS
window.show = function() {
$("ul").animate({ 'height': 30 }, 5000);
$("ul li").css({'visibility':'visible'}).animate({ 'height': 30 }, 5000);
}
window.hide = function() {
$("ul").animate({ 'height': 0 }, 5000);
$("ul li").animate({ 'height': 0 }, 5000, function(){$("ul li").css({'visibility':'hidden'});});
}
也許監守'hide'是不是一個有效的CSS屬性,因此它不知道如何動態顯示。 http://www.w3schools.com/cssref/pr_dim_line-height.asp – 2013-05-05 00:45:57
它確實不是一個有效的CSS值,但jQuery理解它(以及「show」和「toggle」),請參閱http:// api .jquery.com/animate/ – gpothier 2013-05-05 01:00:45
經過了一段時間,我發現問題的原因:jQuery認爲行高是一個數字屬性(不管它是什麼意思,但是例如寬度和高度都不是數字屬性),因此在設置屬性值時不指定單位。它看起來像一個無單位值的行高被視爲'em'單元中的值... – gpothier 2013-05-05 01:04:20