52

我有这个代码:

$.ajax({
        url : url,
        data : {ids : JSON.stringify(jsonids), hotel_id: hotel_id},
        success : function(response)
        {
            $('#be-images ul').prepend(response).fadeIn('slow');
        },
        dataType: 'html'
    });

但是淡入不起作用...我希望将内容添加到前面并淡入...我将如何做到这一点?

提前致谢!

4

3 回答 3

111

假设response是 HTML 然后试试这个:

$(response).hide().prependTo("#be-images ul").fadeIn("slow");

当你这样做时:

$('#be-images ul').prepend(response).fadeIn('slow');

您实际淡入的内容是初始选择器(前面的列表)的结果,它已经可见。

于 2009-12-15T08:55:12.663 回答
42

+1 cletus,但我只是想强调另一种方式。

$('#be-images ul').prepend(
    $(response).hide().fadeIn('slow')
);
于 2009-12-15T13:31:11.557 回答
1

试试这个:HTML

<button>Add</button>
<div id="data"></div>

查询:

$('button').click(function() {
  $('#data').prepend('<div class="item">Test</div>'"');
    $("#data .item:first-child").hide();
   $("#data .item:first-child").fadeIn();
});

现场演示:jsfiddle

于 2017-11-02T15:27:22.440 回答