我有一个测试页面http://www.emoceanstudios.com.au/test.php,这是相关的脚本:
<script type="text/javascript">
function slide_out(){
$('#red-block').animate({
marginLeft: -278
}, 500);
$('#yellow-block').animate({
marginTop: -316
}, 500);
$('#gray-block').animate({
marginLeft: 278
}, 500, function(){
$('#three-color-container').fadeOut(500, function() {
$('#three-color-container-new').fadeIn(500, function() {
window.setTimeout(function(){slide_in()}, 4000);
});
});
});
}
function slide_in(){
$('#three-color-container-new').fadeOut(500, function() {
$('#three-color-container').fadeIn(500, function(){
$('#red-block, #yellow-block, #gray-block').animate({
marginLeft: 0,
marginTop: 0
}, 500, function() {
window.setTimeout(function(){slide_out()}, 4000);
});
});
});
}
window.setTimeout(function(){slide_out()}, 4000);
</script>
现在红色黄色灰色块像这样滑动:出,入,出,入,出然后闪烁(这不是我想要的),仅适用于两个半循环。如果我将计时器从 4000 设置为 6000,它最多可以工作 3 个循环,然后也会中断。
我希望它永远出入入出入出入出入出入出入出入出setTimeout 函数。