【发布时间】:2013-11-27 08:56:52
【问题描述】:
HTML
<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 中为我工作.....
-
是的,它正在工作,但有黑色褪色。那应该是第二张照片。
标签: javascript jquery html css