2014-03-12 21 views
0

我有這段代碼可以從url php輸出更改背景圖片。有人可以幫我整合一個圖片過渡效果到這個腳本。將轉換效果添加到當前腳本

setInterval(function fetchImage() { 

     $.get("test.php", function(data){ // "data" is whatever your php script returns 
      //console.log(data); // for debugging your php response 
      var imageString = 'url(' + data + ') no-repeat'; // Build your background css string 
      $('td#banner').css('background',imageString); // assign the value of imageString to the td's background css property 
     }); 

    }, 2000); 

<td class="banner" id="banner"> 
</td> 
+0

「當前加密」上調用$.fadeIn? – j08691

+0

你得到了什麼錯誤....也是數據定義?做'if(data){var imageString ....}' – Vikram

+0

當前腳本...腳本正常工作我需要添加淡入淡出過渡效果。 – user2789787

回答

0

呼叫$.fadeIn看來你必須確保你的元素設置爲display: none

http://jsfiddle.net/mendesjuan/ZpPPk/3/

$('td#banner').css({ 
    'background-image': 'url(https://www.google.com/images/srpr/logo11w.png)', 
    display: 'none' 
}).fadeIn(1000); 

如果你想要的背景圖像褪色的,而不是前臺,這是實際上很辛苦。你不能使用background-image,你必須在它後面加上一個div,並在

+0

我真的很喜歡這個,你可以給我一個完整的例子,用已經發布的代碼生成 – user2789787

+0

我不確定你不明白什麼,只需在調用結束時添加'.fadeIn()'到'$ ('td#banner').css('background',imageString)'我不想發佈完整的示例,我不打算爲你做,我會告訴你可以做些什麼。看到http://stackoverflow.com/questions/8610973/jquery-change-div-background-image-with-fadein-out和 –

+0

我得到了那部分,我只是不知道使div工作 – user2789787