我有一個無序列表,其中包含1到3個列表項。無序列表(不幸)位於固定高度div
與overflow: hidden
之內。爲集合中的每個元素設置CSS規則
<div id="container">
<ul id="tweets">
<li>
Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Etiam est nisi, congue
id pulvinar eget.
</li>
<li>
Donec nisi dolor, molestie quis varius
a, dictum vel nunc. Morbi odio lorem,
viverra eu semper eu.
</li>
<li>
Mollis ac lorem. Aenean consequat
interdum mi, nec vestibulum metus mollis
non. Curabitur sed.
</li>
</ul>
</div>
如果有3個鳴叫,線高度必須不超過1em的完全配合在容器更。如果只有不到三條推文,線路高度可以達到1.5em以適應網站設計的其他部分。
我想要做一些jQuery魔術來動態更新行高。
var tweet_len = $("#tweets > li").size();
if (tweet_len == 0) {
// append a msg telling user there's no tweets
// (this message looks like a tweet and has line-height: 1.5em)
} else if (tweet_len > 0 && tweet_len < 3) {
$("#tweets li").each(function(){
$(this).css("line-height: 1.5em");
});
}
我試過使用上面的代碼(第6-8行),但它不工作。 (我不認爲我完全理解如何使用.each()。)
我應該在第6-8行上使用什麼代碼將行高更新爲1.5em?
你是第一個幾分之一秒的評論。恭喜! – Jazzerus 2010-12-09 23:06:17