0

我想为从另一个页面加载的数据制作动画效果。

我设法用我在网上找到的一个例子做到了这一点。

我的问题是,我想让这个效果只有在我的 ajax 加载时才起作用。

所以我尝试了将我的 ajax 代码放入.when其中并将股票代码效果放入.done

但它并没有像这样工作。

我还能尝试什么?

$(document).ready(function() { 
        $(function CheckinMap() {
            $.when($.ajax({
                type: "GET",
                url: "default.cs.asp?Process=ViewCheckins",
                success: function(data) {
                $(".newsfeed").append(data);
                },
                error: function(data) {
                $(".newsfeed").append(data);
                }
            })).done();
        });
}); 


        var delay = 2000; // you can change it
        var count = 5; // How much items to animate
        var showing = 3; //How much items to show at a time
        var i = 0;
            function move(i) {
                return function() {
                    $('#feed'+i).remove().css('display', 'none').prependTo('.newsfeed');
                    }
            }
            function shift() {
                var toShow = (i + showing) % count;
                $('#feed'+toShow).slideDown(1000, move(i));
                $('#feed'+i).slideUp(1000, move(i));
                i = (i + 1) % count;
                setTimeout('shift()', delay);
            }    
        $(document).ready(function() {
            setTimeout('shift()', delay);
        });

外部数据

                        <div class="metadata" id="feed0">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ Amphi I @ NY</span>
                                <span></span>
                                <span>-5276 seconds ago</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>

                        <div class="metadata" id="feed1">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ Flaming Buddha House</span>
                                <span></span>
                                <span>18 hours ago</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>

                        <div class="metadata" id="feed2">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ Bar @ NY</span>
                                <span></span>
                                <span>19 hours ago</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>

                        <div class="metadata" id="feed3">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ Gym @ NY</span>
                                <span></span>
                                <span>8 hours ago</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>

                        <div class="metadata" id="feed4">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ Bar @ NY</span>
                                <span></span>
                                <span>yesterday</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>

                        <div class="metadata" id="feed5">
                            <div class="userinfo">
                                <span><strong>&nbsp;</strong> @ NY</span>
                                <span></span>
                                <span>yesterday</span>
                            </div>
                            <div class="commonfriends">                               
                            </div>                                
                            <div class="tools">                               
                            </div>  
                        </div>
4

1 回答 1

0

我想您需要将“动画”代码放入 ajax 的成功回调函数中。

success : function (data) { [animationcodehere] }
于 2012-06-06T09:26:28.490 回答