1

jqueryサイクルをtumblrフォトセットで動作させようとすると、フォトセットイメージと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 に答える