問題は、fadeOutアクションのコールバック関数を使用して次のステップをトリガーしていることです。したがって、次のfadeInは、fadeOutが完了した後に発生します。代わりに、遅延後にフェードインを発生させる必要があります。この方法を使用して、queueこれを実現できます。
.delay(timing).queue(function() {
function2();
$(this).dequeue(); // Keeps the queue running, it stops if you don't do this
}).fadeOut("slow", 0.3);
ここにフィドルを作成しましたhttp://jsfiddle.net/e8W5E/実際に動作することを示します
編集roXonのコメントに応えて、次のように、よりエレガントなソリューションを作成できます。HTMLが更新され、冗長なカウントが削除されます...
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
jQueryは次のようになります...
$(function() {
// These are the elements we will rotate
var $blocks = $(".block");
// Set up the initial elements to 0.3 opacity
$blocks.not(":eq(0)").fadeTo("fast", 0.3);
// This is our repeating function
var go = function($el, i, high, low, t) {
$el.eq(i).fadeTo("slow", high)
.delay(t)
.queue(function() {
// The next index is 1 + the current index
// use modulus to repeat back to the beginning
var next = (i + 1) % $el.length;
go($el, next, high, low, t);
$(this).dequeue();
})
.fadeTo("slow", low);
};
// Start fading in and out
go($blocks, 0, 1, 0.3, 1000);
})();
そのクラス名で必要な数のブロックを追加でき、それはfadeInおよびfadeOutローテーションに含まれます。そしてフィドルhttp://jsfiddle.net/e8W5E/1/