每次运行后运行功能

时间:2012-10-26 00:31:56

标签: jquery each tumblr jquery-cycle

尝试让jquery循环与tumblr photoset一起工作,因为photoset图像和div'.html_photoset'是用每个函数动态加载的,循环无法获取div'.html_photoset'

$(function(){
$('.html_photoset').cycle({ fx: 'fade' });
$('.html_photoset').each(function() {
                var tumblr_post_id = $(this).attr('id').split('_')[1];
                $(this).empty();
                var this_photoset = this;
                $.getJSON('/api/read/json?id='+ tumblr_post_id +'&callback=?', function(response){
                    var photos = response['posts'][0]['photos'];
                    $.each(photos, function() {
                        var photo_url = this['photo-url-1280'];
                        var photo_caption = this['caption'];
                        var photo_markup = '<img src="'+ photo_url +'"/>';
                        $(this_photoset).append(photo_markup);
                    });
                });
            }); 
}); 

1 个答案:

答案 0 :(得分:0)

你可能想放手一搏(尚未测试过):)

$('.html_photoset').cycle({ fx: 'fade' });

$('.html_photoset').on('refresh', function() {
  $('.html_photoset').cycle({ fx: 'fade' });
});


$('.html_photoset').each(function() {
            var tumblr_post_id = $(this).attr('id').split('_')[1];
            $(this).empty();
            var this_photoset = this;
            $.getJSON('/api/read/json?id='+ tumblr_post_id +'&callback=?', function(response){
                var photos = response['posts'][0]['photos'];
                $.each(photos, function() {
                    var photo_url = this['photo-url-1280'];
                    var photo_caption = this['caption'];
                    var photo_markup = '<img src="'+ photo_url +'"/>';

                    // calling the cycle again.
                    $(this_photoset).append(photo_markup).trigger('refresh');
                });
            });
        }); 
});