リストをアニメーション化するための小さなスクリプトを作成しています。これが私のhtml構造です:
<ul>
<li class="slider"> Item-1 </li>
<li class="slider"> Item-2 </li>
<li class="slider"> Item-3 </li>
...
<li class="slider"> Item-13 </li>
<li class="slider"> Item-14 </li>
<li class="slider"> Item-15 </li>
</ul>
<button> Next </button>
一度に4つのliのみを表示しています。「次へ」ボタンは、表示された4つのliをフェードアウトします。次の4つのliをフェードインします。しかし、フェードは両方を一緒に適用しています。最初のフェードでコールバック関数を使用しようとしましたが、機能させることができません。
スクリプトは次のとおりです。
$('li:gt(3)').css('display', 'none');
//Define the interval of li to display
var start = 0;
var end = 4;
//Get the ul length
var listlength = $("li").length;
$("button").click(function() {
// FadeOut the four displayed li
$('ul li').slice(start,end).fadeOut(500, function(){
// Define the next interval of four li to show
start = start+4;
end = end+4;
// Test to detect the end of list and reset next interval
if( start > listlength ){
start = 0;
end = 4;
}
//Display the new interval
$('ul li').slice(start,end).fadeIn(500);
});
});
手がかりはありますか?