HTML改变图像(背景)每10秒
<div id="background">
<img src="#" alt="Background Image" class="first"/>
<img src="#" alt="Background Image" class="second"/>
</div>
我没有一个SRC添加,因为它会降低我的网页的加载时间。 (demo)
JQuery的
var current = "first";
window.setInterval(function() {
if(current == "first") {
$("#background .second").prop("src", getMessage());
setTimeout(function(){
$("#background .second").animate({
opacity: 1
}, 1000);
$("#background .first").animate({
opacity: 0
}, 1000);
},1000);
current = "second";
} else if (current == "second") {
$("#background .first").prop("src", getMessage());
setTimeout(function(){
$("#background .first").animate({
opacity: 1
}, 1000);
$("#background .second").animate({
opacity: 0
}, 1000);
},1000);
current = "first";
}
getMessage()
}, 5000);
所以我有SRC链接到我的图像,这是通过随机function getMessage()
选择并虽然示出了图像,其他的IMG标记将改变SRC和等待的阵列第二或两个以获得该图像加载,然后它将显示一个动画。
但是现在的问题是:他不显示第二张图片时,第一张照片了不透明度0,第二个画面有不透明度1 .. 编辑:问题是图片的之间的黑色褪色。
在此先感谢!
它在IE中为我工作..... –
是的,它的工作,但有一个黑色的褪色。这应该是第二张照片。 – MikaldL