试试这个代码:
$(document).ready(function(){
window.setInterval(function(){
$("#background2").fadeIn(timeInOut,function(){
$("#background3").fadeIn(timeInOut,function(){
$("#background2").css("display","none");
$("#background3").fadeOut(timeInOut);
});
});
}, timeInOut*3)
});
您也可以不使用超时并执行此操作:
$(document).ready(function(){
loopFade()
});
function loopFade(){
$("#background2").fadeIn(timeInOut,function(){
$("#background3").fadeIn(timeInOut,function(){
$("#background2").css("display","none");
$("#background3").fadeOut(timeInOut, loopFade);
});
});
}
您可能还希望在background2
淡出时background3
淡入。更改代码:
方式#1:
$(document).ready(function(){
window.setInterval(function(){
$("#background2").fadeIn(timeInOut,function(){
$("#background3").fadeIn(timeInOut,function(){
$("#background2").css("display","none");
$("#background3").fadeOut(timeInOut);
});
});
}, timeInOut*2)
});
方式#2:
$(document).ready(function(){
loopFade()
});
function loopFade(){
$("#background2").fadeIn(timeInOut,function(){
$("#background3").fadeIn(timeInOut,function(){
$("#background2").css("display","none");
$("#background3").fadeOut(timeInOut);
loopFade()
});
});
}