我不知道我是否理解你的問題。但是,這是我如何實現這一目標的代碼。
<ul id="accordion">
<li>
<a href="#recent" class="heading">Application</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Forum</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Guilds</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
<li>
<a href="#archive" class="heading">Projects</a>
<ul>
<li><a href="#">January 2009</a></li>
<li><a href="#">December 2008</a></li>
<li><a href="#">November 2008</a></li>
<li><a href="#">October 2008</a></li>
<li><a href="#">September 2008</a></li>
</ul>
</li>
CSS
ul#accordion{
float:right;
}
ul#accordion, ul#accordion ul { list-style: none; margin: 0; }
ul#accordion a.heading {
color: black;
display: block;
font-size:16px;
font-weight:bold;
text-decoration: none;
margin-right:30px;
}
ul#accordion li ul a { font-size:14px;color: black; text-decoration: none;}
ul#accordion li ul a:hover { text-decoration: underline; }
#accordion li ul { display: none; }
#accordion li.current ul { display: block; }
JS
$(document).ready(function() {
$('ul#accordion a.heading').click(function() {
$(this).css('outline','none');
if($(this).parent().hasClass('current')) {
$(this).siblings('ul').slideUp('slow',function() {
$(this).parent().removeClass('current');
});
} else {
$('ul#accordion li.current ul').slideUp('slow',function() {
$(this).parent().removeClass('current');
});
$(this).siblings('ul').slideToggle('slow',function() {
$(this).parent().toggleClass('current');
});
}
return false;
});
});
這裏是一個jsFiddle
非常感謝您!有沒有什麼辦法可以讓我在添加填充時不會相互重疊? 此外,我正在使用jquery菜單。 http://users.tpg.com.au/j_birch/plugins/superfish/ – Zifaun 2013-02-17 12:43:51