function change2(){ document.getElementById("img2").style.zIndex='2'; document.getElementById("img1").style.zIndex='1'; document.getElementById("img1").style.opacity='1'; $("#img2").animate({opacity:'0'},2000); }function change3(){ document.getElementById("img1").style.zIndex='2'; document.getElementById("img2").style.zIndex='1'; $("#img1").animate({opacity:'0'},2000); document.getElementById("img2").style.opacity='1'; }function change4(){ setTimeout("change2()",5000); setTimeout("change3()",12000); setTimeout("change4()",14000); } `
通过控制图片的z-index和opacity属性实现图片的交替渐变。