在一个循环的两个div之间淡入/淡出

问题描述:

我将如何使两个div在两个之间交替淡入/淡出,以便一次只能看到一个?还可以使其永无止境地循环吗?

How would i go about make two divs fade in/out alternating between the two, so that only one is visible at a time? And also make it in a never ending loop?

提前谢谢!

我知道应该使用.fadeOut和.fadeIn完成-但不确定如何使其一遍又一遍地循环.

I know it should be done with the .fadeOut and .fadeIn - but not sure how to make it loop over and over again.

这是我自己的小提琴版本

Here's my own version a la fiddle

http://jsfiddle.net/3KydB/

window.switchIn = function () {
    $('.red').fadeToggle(function() {
        $('.blue').fadeToggle(function() {
            setTimeout(function() {window.switchOut();}, 500);
        });
    });

}

window.switchOut = function () {
    $('.blue').fadeToggle(function() {
        $('.red').fadeToggle(function() {
            setTimeout(function() {window.switchIn();}, 500);
        });
    });

}

setTimeout(function() {window.switchIn();}, 500)