1

试图让 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);
                    });
                });
            }); 
}); 
4

1 回答 1

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');
                });
            });
        }); 
});  
于 2012-10-26T01:15:57.980 回答