ulリスト内の任意のアイテムをクリックすると、クリックしたアイテムを除くすべてのアイテムが表示/非表示になります。私はslideToggleを使って素敵なアニメーションを作ろうとしています。ただし、同じ項目リストを繰り返しクリックすると、リストの順序が変更されます。
HTML :
<ul class="imp">
<li style="background: hotpink;">1</li>
<li style="background: lightgreen;">2</li>
<li style="background: lightblue;">3</li>
<li style="background: bisque;">4</li>
<li style="background: pink;">5</li>
<li style="background: wheat;">6</li>
</ul>
jQuery
$('li').click(function () {
if ($(this).closest('ul').find('li').is(':hidden')) {
$(this).prependTo(".imp").fadeIn("slow");
}
$(this).closest('ul').find('li').not($(this)).slideToggle("slow", function () {
if ($(this).closest('ul').find('li').is(':hidden')) {
$(this).prependTo(".imp");
}
});
});
CSS
ul{
list-style: none;
}
li {
cursor: pointer;
width: 100px;
background-color: red;
text-align: center;
height: 25px;
}