将转换效果添加到当前脚本

时间:2014-03-12 21:06:54

标签: javascript jquery css

我有这个代码来改变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> 

1 个答案:

答案 0 :(得分: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并在其上调用$.fadeIn

相关问题