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